开发者

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

开发者 https://www.devze.com 2023-04-04 18:07 出处:网络
开发者_如何学GoI 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 possib
开发者_如何学Go

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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号