MVC2 - 从更新方法中排除日期和时间列
我正在尝试更新一条记录,并希望从更新中排除一列,我有一个用 GetDate() 填充的字段作为 sql 中的默认值,因此当更新发生时,我希望该字段保持原样,
[ScaffoldColumn(false)]
[Column] public DateTime RegisteredDate { get; set; }
我尝试使用 dataannotaions 和 HiddenInput(DisplayValue = false) 中的 ScaffoldColumnFalse ,但是当我尝试保存更改时,会抛出错误
sqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
根据我的理解,这是由于传递给 RegisterdDate 的空值而引发的字段,
我还尝试在 ActionResult 存根中使用绑定排除但无济于事
public ActionResult Edit([Bind(Exclude = "RegisteredDate")] Customer customer)
有人对我在这里出错的地方有任何想法吗?
亲切的问候
利亚姆
I am tring update a record and want to exclude one column from the update, i have this field that is populated with GetDate() as a default value in sql, so when the update takes place i want this field to be left as it is,
[ScaffoldColumn(false)]
[Column] public DateTime RegisteredDate { get; set; }
Ive tried using both ScaffoldColumnFalse from dataannotaions and HiddenInput(DisplayValue = false) but when i try to save the changes an error is thrown
sqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
From what i understand this is thrown due to a null value being passed to the RegisterdDate field,
Ive also tried using bind Exclude in the ActionResult stub to no avail
public ActionResult Edit([Bind(Exclude = "RegisteredDate")] Customer customer)
Anyone any ideas on where I am going wrong here?
Kind Regards
Liam
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 Steve Sanderson 的博客,部分验证在 ASP.NET MVC 2 中。他的方法是仅验证从视图传入的值。这可能适用于您的情况。
Have a look at Steve Sandersons blog, Partial Validation in ASP.NET MVC 2. His approach is to validate only incoming values from the view. This may work in your case.