asp.net - MVC models' unique field Create-Edit Complication -
i have model in mvc that;
public class employee { public int employeeid { get; set; } [required] [emailaddress] [displayname("email")] [remote("doesemailexist", "employee", httpmethod = "post", errormessage = "email exists. please come in different email.")] public string email { get; set; } } on create action, okey, works great. on edit action, programme see email address exist. , cannot update employee same email address. can do?
you utilize additionalfields property of remoteattribute include employeeid in validation. in action method, if employeeid=null validation fails if matching email found, otherwise check matching emails different employeeid
asp.net asp.net-mvc asp.net-mvc-4 data-annotations
No comments:
Post a Comment