Mvc4 RTM validation throwing an error

旧巷老猫 提交于 2019-12-04 07:28:16

In addition to adding [DataMember(IsRequired = true)] to the property, you'll also need to ensure that the attribute [DataContract] is applied at the class level.

The data entry DataContract is being consumed by the UI to create the data entry form and the back-end whenever the form is posted. So, is it safe to say that [DataMember(IsRequired = true)] is needed for the back-end and [Required(ErrorMessage = @"Product type is required)] is needed for form validation so you can access the error message?

I'm not sure why we have to do both. Why can't we have a single attribute to be used by front-end and server side?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!