4

当我通过自动生成的 EF 从表单更新表时,如果我因为不想可编辑而从视图表单中删除了一些数据列,那么这些列将更新为空值,如何避免这种行为?我在这里读到:实体框架:忽略从模型中删除它的列,但我并不总是想忽略这些数据列。

谢谢!

4

2 回答 2

3

另一种方法是使用注释

[HttpPost]
public virtual ActionResult Edit(
    [Bind(Prefix="", Include="field1", Exclude="field2")]MyClass myClass)
{
  ....
于 2011-05-20T19:13:19.263 回答
2

asp.net MVC为你提供UpdateModel方法,看重载

protected internal void UpdateModel<TModel>(
TModel model,
string prefix,
string[] includeProperties,
string[] excludeProperties
)
where TModel : class

使用它,您可以按名称排除或包含特定属性

于 2011-05-20T18:35:06.147 回答