I have below model class. that is shared by multiple views.
Now, For the view1.cshtml both validation attribute(i.e RegularExpression
,Required
) working fine so I don't need to do anything for that.
Problem is when I submit my second view2.cshtml I want to remove Required
validation attribute but not RegularExpression
.
Model class has below property
[RegularExpression(@"[A-Za-z]{5}\d{4}[A-Za-z]{1}", ErrorMessage = "Invalid")]
[Required(ErrorMessage = "The PAN no field is required")]
public string pan { get; set; }
I tried below code to remove Required validation but it also remove RegularExpression validation.
ModelState.Remove("pan");
if (ModelState.IsValid)
{
}