I have a model class with 6 fields(all with required field validation). I have two views which are using this model. I have three fields in one view(lets say abc.cshtml) and all six in another(lets say xyz.cshtml) The problem is,when I am submitting the form in abc.cshtml and checking ModelState.IsValid property in Controller,it is validating all fields even which are not presented on view,so this property is appears to be false. This is my model
public class UserModel
{
[Required(ErrorMessage = "Enter UserName")]
public string UserName { get; set; }
[Required(ErrorMessage = "Enter Password")]
public string Password { get; set; }
[Required(ErrorMessage = "Enter Firstname")]
public string Firstname { get; set; }
[Required(ErrorMessage = "Enter LastName")]
public string LastName { get; set; }
[Required(ErrorMessage = "Enter Contact")]
public string Contact { get; set; }
[Required(ErrorMessage = "Enter Address")]
public string Address { get; set; }
}
I have only Username, Firstname and Lastname in one view and all six in another. How can I tackle this issue?