I have a simple form that posts a ViewModel to an Action method. Before saving the information the ModelState is checked with a standard if(ModelState.IsValid)
. Then a new object is created and saved. Great, it works.
Recently another dev went in and created a new view with my original ViewModel. He also added a new [Required] property to the ViewModel to make his logic work.
By doing that his logic broke my initial logic. Because my initial view doesn't use his new Required property so ModelState.IsValid
check now fails and my code doesn't run.
What is the best approach to take here ? Though I don't want to but should I get rid of ModelState.IsValid check on my Post actions or can I somehow flag his new property to Not be required when used in my original views or when being posted in my action method ?
Thank you in advance.