Disable required validation by JavaScript

前端 未结 7 865
半阙折子戏
半阙折子戏 2020-12-19 02:11

I have a create form to create an object. The create model has some properties that are only visible (.hide, .show()) if a checkbox is checked and that are marked required (

7条回答
  •  天命终不由人
    2020-12-19 02:54

    You could implement a custom validator like "RequiredIf".

    That will keep your model design quite obvious (unlike client-side-only solutions proposed). This allows you to keep the validation logic separate from display logic (that's what MVC is all about).

    See this answer : RequiredIf Conditional Validation Attribute

    and ultimately that blog post : Conditional Validation in ASP.NET MVC 3

    cheers!

提交回复
热议问题