How to make validation optional for complex type in asp.net mvc?

I want to display an editor for type User. The user contains an Address field of type Address. I created an editor template for the Address type so that it is reused.

I do not want the Address field to be required to create a user. But some fields are necessary for the address, for example, country, state, etc.

I want to check the address, if I get any data for it, if I get nothing, then I do not want to return any validation error to the user interface for the address. Then I would only return validation errors for the user.

What would be the best way to do this?

Thank,

+3
source share
3 answers

, Binder . Address .

0

Simon J Ince Microsoft. . , . RequiredIf, , . , , , , .

+1
0

Source: https://habr.com/ru/post/1794154/


All Articles