我有一个这样的 js 对象构建:
var entity = new Object();
entity["1"] = Property1.GetValue();
entity["2"] = Property2.GetValue();
entity["3"] = Property3.GetValue();
entity["4"] = Property4.GetValue();
entity["5"] = Property5.GetValue();
entity["6"] = Property6.GetValue();
entity["7"] = Property7.GetValue();
entity["8"] = Property8.GetValue();
entity["9"] = Property9.GetValue();
entity["10"] = Property10.GetValue();
entity["11"] = Property11.GetValue();
entity["12"] = Property12.GetValue();
entity["13"] = Property13.GetValue();
entity["14"] = Property14.GetValue();
entity["15"] = Property15.GetValue();
我像这样发布它:
var data = JSON.stringify(
{
entityID: 1,
data: entity
});
$.ajax({
type: "POST",
url: "/Entity/Update",
data: data,
contentType: "application/json",
traditional: true,
success: function (data) {
alert("koko");
},
error:function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(ajaxOptions);
alert(thrownError);
}
});
帖子是,但 MVC 控制器为 data 参数获取了一个空参数。
MVC方法:
public void Update(int entityID, IDictionary<string, object> data)
问题是值可以是不同的类型,而不仅仅是字符串或整数。那就是问题所在。有没有办法让默认模型绑定器正确读取对象,还是我必须编写自定义模型绑定器?