JS Object To C# ASP.Net ModelBind
之前做项目的时候发现,Jquery自带的Form 序列化函数。与asp.net 里边的Modelbinding格式不匹配,所以写了一个可以把前端的Object对象序列化成ModelBinding认识的数据格式的函数
//序列化对象
var serializedObj = function (obj) {
var arr = [];
recursiveSerialization(obj, arr, '');
return arr.join('&');
}
var recursiveSerialization = function (obj, arr, head) {
if (obj == '' || typeof obj == 'undefined') {
return;
}
if (Array.isArray(obj)) {
for (var i = 0; i < obj.length; i++) {
var newhead = head + '[' + i + ']';
recursiveSerialization(obj[i], arr, newhead);
}
}
else if (typeof obj == 'number' || typeof obj == 'boolean' || typeof obj == 'string') {
arr.push(head + '=' + obj + '');
} else {
for (var key in obj) {
var newhead
if (head == "") {
newhead = key;
} else {
newhead = head + '.' + key;
}
recursiveSerialization(obj[key], arr, newhead)
}
}
}
JS Object To C# ASP.Net ModelBind的更多相关文章
- RSA加密前端JS加密,后端asp.net解密,报异常
RSA加密前端JS加密,后端asp.net解密,报异常 参考引用:http://www.ohdave.com/rsa/的JS加密库 前端JS加密代码: function GetChangeStr() ...
- JS Object.defineProperties()方法
JS Object.defineProperties()方法 描述: Object.defineProperties()方法为目标对象同时配置多个属性. 语法: Object.defineProper ...
- js & Object reference bug
js & Object reference bug bug object ref bug onClickButton (type = ``) { let { publishDate: publ ...
- JS Object Deep Copy & 深拷贝
JS Object Deep Copy & 深拷贝 针对深度拷贝,需要使用其他方法 JSON.parse(JSON.stringify(obj));,因为 Object.assign() 拷贝 ...
- JS Object Deep Copy & 深拷贝 & 浅拷贝
JS Object Deep Copy & 深拷贝 & 浅拷贝 https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Refe ...
- js & object & prototype & __proto__ & prototype chain
js & object & prototype & proto & prototype chain constructor prototype === instance ...
- JS - Object and Property的删除用法
在JS中,Object和Property的删除用法: var myObject = {name:'jimmy', age:12, height:123} delete myObject["j ...
- js object(对象)
http://www.cnblogs.com/pingchuanxin/p/5773326.html Object(对象)是在所有的编程语言中都十分重要的一个概念,对于事物我们可以把他们看作是一个对象 ...
- js object 常用方法总结
Object.assign(target,source1,source2,...) 该方法主要用于对象的合并,将源对象source的所有可枚举属性合并到目标对象target上,此方法只拷贝源对象的自身 ...
随机推荐
- python中的 try...except...finally 的用法
python中的 try...except...finally 的用法 author:headsen chen date:2018-04-09 16:22:11 try, except, final ...
- ios 统一设计,iOS6也玩扁平化
转:http://esoftmobile.com/2014/01/14/build-ios6-ios7-apps/ 前言 前段时间,苹果在它的开发者网站上放出了iOS系统安装比例,其中iOS7占到78 ...
- MySQL 1067
今天在云服务器上装mysql的时候,启动突然报了一个“1067 进程意外终止”的错误,这个错误之前是遇到过的,之前因为my.ini配置basedir路径的时候没有正确配置导致了这个错误,但是今天又出现 ...
- Backtracking is a form of recursion.
w https://www.cis.upenn.edu/~matuszek/cit594-2012/Pages/backtracking.html Starting at Root, your opt ...
- 【总结】两种 NIO 实现:Selector 与 Epoll
时间2012-11-17 08:38:42 开源中国新闻原文 http://my.oschina.net/ielts0909/blog/89849 我想用这个话题小结下最近这一阶段的各种测试和开发. ...
- Android—Http连接之GET/POST请求
在Android SDK中提供了Apache HttpClient(org.apache.http.*)模块.在这个模块中涉及到两个重要的类:HttpGet和HttpPost. 创建步骤: ...
- 对 tensorflow 中 tf.nn.embedding_lookup 函数的解释
http://stackoverflow.com/questions/34870614/what-does-tf-nn-embedding-lookup-function-do embedding_l ...
- python 对象和类
python中所有数据都是以对象形式存在.对象既包含数据(变量),也包含代码(函数),是某一类具体事物的特殊实例. 面向对象的三大特性为封装.继承和多态. 1.定义类 #定义空类 class Pers ...
- selenium的下拉选择框
今天总结下selenium的下拉选择框.我们通常会遇到两种下拉框,一种使用的是html的标签select,另一种是使用input标签做的假下拉框. 后者我们通常的处理方式与其他的元素类似,点击或使用J ...
- php 内存泄漏
所谓内存泄漏是指进称在执行过程中,内存的占有率逐步升高,不释放, 系统所拥有的可用内存越来越少的现象. php-fpm耗光内存,不释放,就是所谓的内存泄漏,内存泄漏对长期运行的程序有威胁,所以应该定期 ...