我想使用模型绑定来保持我的控制器看起来更干净,你可以看到使用模型绑定有多好:
public ActionResult Create(Person personToCreate)
{
//Create person here
}
VS
public ActionResult Create(string firstName, string lastName, string address, string phoneNum, string email, string postalCode, string city, string province, string country)
{
//Create person here
}
在进行模型绑定时,我们可以在Html.TextBox("")
jquery怎么样?当我对$.post(url, data, callback, dataType)
进行$.ajax(options)
或Create(Person personToCreate)
调用时,如何正确填充Person对象?
答案 0 :(得分:4)
你需要:
对于为什么绑定到人的行为可能与为每个属性指定单独的动作参数不同,数字2是最重要的。如果您的类型具有名为“Foo”的非可空属性,则无法在表单中提供foo项将阻止绑定。