Conditional validation on model in MVC

后端 未结 4 425
半阙折子戏
半阙折子戏 2020-12-01 06:39

I have a view & model that I use for both the edit and the insert page for a record. One of the business requirements is that a certain field is required on edit but not

4条回答
  •  时光说笑
    2020-12-01 07:19

    You could use the RequiredIf validation attribute from the MVC Foolproof Validation project. I've used it on projects to enable just the functionality you require.

    An alternative would be to use the RemoteAttribute and implement the logic yourself in a method.

提交回复
热议问题