I am using MVC-View Model, EF Model first
I am having problems with two of my Properties inside my View Model which is following:
[Required]
public string TeamName { get; set; }
[Required]
public string ConsultantName { get; set; }
These two properties can get disabled depending on what SubjectTypeName the user choose
[Required]
public string SubjectTypeName { get; set; }
Lets say I choose a SubjectTypeName Value and my TeamName and ConsultantName gets disabled, but when I want to save the form I get error beacuse my ModelState.IsValid gets false. And its the [Required] that makes it "false".
Is there any easy solutions for this? Like a easy Jquery code to inactive TeamName and ConsultantName from the validation so my ModelState.IsValid becomes "true"?
Thanks in Advance!
You may take a look at the following blog post which illustrates how you could write a custom
[RequiredIf]validation attribute that will handle conditional validation on the server and on the client. You can directly download the Mvc.ValidationToolkit which contains this validation attribute.