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,如需转载请自行联系原作者