【发布时间】:2011-08-09 06:38:58
【问题描述】:
我的 MVC3 Web 应用程序中有一些模型,当用户创建或编辑对象/实体时,它们的字段需要在“幕后”设置。
我正在尝试找出有关这些类型字段的最佳做法。
例如...
public class EntityA {
public int Id { get; set; }
public string Title { get; set; }
...
[ForeignKey("User")]
public int UpdatedBy_Id { get; set; }
public virtual User UpdatedBy { get; set; }
}
为此创建和编辑视图允许用户编辑“标题”字段,但“UpdatedBy”字段需要在插入或更新实体时由应用设置。
最好在视图上放置一个隐藏字段并在那里设置“UpdatedBy_Id”,还是使用模型属性“get/set”主体来这样做? ...或者...这应该在控制器中的 HttpPost 上吗?
【问题讨论】:
-
您不能使用用户会话数据(通过会员资格或任何提供者)来检索服务器中的 updatedBy 值吗?
标签: asp.net-mvc-3 models edit hidden