使用jquery传递复杂Json数据——[ModelBinder(typeof(JsonBinder<复杂实体类>))]

来源:互联网 发布:windows to go u盘 编辑:程序博客网 时间:2024/06/05 11:37

调用jQuery的ajax方法时,jQuery会根据post或者get协议对参数data进行序列化;

如果提交的数据使用复杂的json数据,例如:

{userId:32323,userName:{firstName:"李",lastName:"李大嘴"}}

那么服务器是无法正常接收到完整的参数,因为jQuery对data的序列化,是使用了键值对拼装的方式;

参数拼装成 userId=32323&userName=object ; userName所指向的对象被序列化成字符串"object"

 

        public ActionResult Add([ModelBinder(typeof(JsonBinder<CostItem>))]CostItem costItem)

0 0