脚本代码:
var data = { "per.Name": "hu", "per.Gender": "yulin", "list[0].Name": "aaa", "list[0].Gender": "男", "dic[hh].Gender":"Nan","dic[hh].Name":"shaoshuai" }
$.post("/home/test4", data, function (hh) {
alert(hh);
}, "test");
后台代码:
public ActionResult Test4(Person per,List<Person>list,Dictionary<string,Person>dic)
{
return Content("大家好才是真的好");
}
person类
public class Person
{
public string Name
{
get;
set;
}
public string Gender
{
get;
set;
}
}
可以看出如果参数是复杂类型,则直接在参数名称后面加“.”,然后加上属性名称(记住必须是属性名,不能使字段)作为键;如果参数是集合类型,则直接用集合名加上索引加“.”加上属性名表示键;如果参数是字典型,则直接用字典名加上key加“.”然后加上属性名表示键。
如果这种绑定能够理解了,则所有的绑定方式都能够用很好的使用。