Using Data Annotations to make a field required while searching for another in a form mvc 3

元气小坏坏 提交于 2019-12-11 17:26:57

问题


I have a form with multiple search filters. Let's say Order Id, PO Num, Store Code, Status, etc. I would like to make Store Code required while user searches using PO Num. Is it possible using Data Annotation in asp.net mvc 3?


回答1:


One option is you have your own custom validation and implement IValidatableObject See: ASP.NET MVC Conditional validation

Note though this is only on the server side. There will be no client side validation here. If you want client side validation as well on this conditional validation check out:

http://blogs.msdn.com/b/simonince/archive/2011/02/04/conditional-validation-in-asp-net-mvc-3.aspx



来源:https://stackoverflow.com/questions/7422628/using-data-annotations-to-make-a-field-required-while-searching-for-another-in-a

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