我不确定这是否是DefaultModelBinder类中的错误或者是什么.但UpdateModel通常不会更改模型的任何值,除了它找到匹配的值.看看以下内容:
[AcceptVerbs(HttpVerbs.Post)]
public ViewResult Edit(List<int> Ids)
{
// Load list of persons from the database
List<Person> people = GetFromDatabase(Ids);
// shouldn't this update only the Name & Age properties of each Person object
// in the collection and leave the rest of the properties (e.g. Id, Address)
// with their original value (whatever they were when retrieved from the db)
UpdateModel(people, "myPersonPrefix", new string[] { "Name", "Age" });
// ...
}
Run Code Online (Sandbox Code Playgroud)
会发生什么是UpdateModel创建新的 Person对象,从ValueProvider分配它们的Name和Age属性并将它们放在参数List <>中,这使得其余的属性设置为它们的默认初始值(例如Id = 0),那么什么是去吧?