Mapping complex JSON in MVC Action argument (MVC中Json 复杂对象的使用)

JS source

    <script src="/Script/jquery-1.5.1.min.js" type="text/javascript"></script>
    <script src="/Script/jquery.json-2.2.min.js" type="text/javascript"></script>

Mapping Entity



public class someList
{
   public string strOne {get; set;}
   public string strTwo {get; set;}
}
public class Entity
{
    public string EntityMember;
    public List<someList> entityList;
}

Argument



public ActionResult MyControllerAction(Entity objEntity)

JS client


$.ajax({                                                    
        url: "/MyController/MyControllerAction",                                       
        type: "POST",                                           
        data: JSON.stringify(Entity),                          
        dataType: "json",                                       
        contentType: "application/json; charset=utf-8",         
        success: function (data) {                              
            ....                                     
        }                                                       
    });  

My Problems

  • 
    
    data: JSON.stringify(Entity)//Jquery 默认会转Json obj成键值对,所以必须传送String
  • 
    
    var Entity = {};//需要跟mapping的类名或action的参数名一致

本文转自today4king博客园博客,原文链接:http://www.cnblogs.com/jinzhao/articles/2045774.html,如需转载请自行联系原作者
上一篇:Scala高阶函数示例


下一篇:熟悉云数据库 Mysql 版控制台|学习笔记