c# - MVC Model Validation Multiple View -
i have model class 6 fields(all required field validation). have 2 views using model. have 3 fields in 1 view(lets abc.cshtml) , 6 in another(lets xyz.cshtml) problem is,when submitting form in abc.cshtml , checking modelstate.isvalid property in controller,it validating fields not presented on view,so property appears false. 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 username, firstname , lastname in 1 view , 6 in another. how can tackle issue?
public class basemodel{ [required(errormessage = "enter firstname")] public string firstname { get; set; } [required(errormessage = "enter lastname")] public string lastname { get; set; } [required(errormessage = "enter username")] public string username { get; set; } } public class usermodel : basemodel { [required(errormessage = "enter password")] public string password { get; set; } [required(errormessage = "enter contact")] public string contact { get; set; } [required(errormessage = "enter address")] public string address { get; set; } } hope reduce redundancy , work different view , think best way tackle kind of problem
Comments
Post a Comment