Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
0 like 0 dislike
2.2k views
in .Net Framework by 39 42 54
I am working on an MVC solutions and I want to exclude a Required Field from ModelState Validation, Even When It's Required in the Database, How can I do that in MVC?

1 Answer

0 like 0 dislike
by 39 42 54
 
Best answer

Exclude a Required Field from ModelState Validation in MVC

To Exclude a Required Field from ModelState Validation, Even When It's Required in the Database , you should follow the below steps in details:

  1. It's necessary to remove the property from the model :

     ModelState.Remove("PropertyName")
    
  2. It's advisable to assign a default value to this property , In the example below, I use an empty string "" for string property

     model.ProperityName = ""
    
If you don’t ask, the answer is always NO!
...