相关疑难解决方法(0)

使用一组复杂数据类型调用UpdateModel会重置所有非绑定值吗?

我不确定这是否是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),那么什么是去吧?

asp.net-mvc model-binding updatemodel

8
推荐指数
1
解决办法
5643
查看次数

标签 统计

asp.net-mvc ×1

model-binding ×1

updatemodel ×1