Multiple remote validation attribute in ASP.NET MVC4
asp.net, asp.net-mvc, attributes, c#, validation
Solution
See below an example:
[Required]
[Display(Name = "Social Security Number:")]
[Remote("ValidSocialSecurityNumber", "Applicant")]
public string SocialSecurityNumber { get; set; }
Your Action
public JsonResult ValidSocialSecurityNumber([Bind(Prefix = "SocialSecurityNumber ")] string ssn)
{
if (!isSocialSecurityNumberValid)
{
return Json("Invalid.", JsonRequestBehavior.AllowGet);
}
if (isSocialSecurityNumberExists)
{
return Json("Already exists.", JsonRequestBehavior.AllowGet);
}
return Json(true, JsonRequestBehavior.AllowGet);
}
Problem
I've got a problem that I can't figure how to solve. I have a remote validation in a model, just like this: ``` [Required] [Display(Name = "Social Security Number:")] [Remote("IsSocialSecurityNumberValid", "Applicant", ErrorMessage = "Invalid.")] public string SocialSecurityNumber { get; set; } ``` But there's another validation that I would like to apply, that is: ``` [Remote("SocialSecurityNumberExists", "Applicant", ErrorMessage = "Already exists.")] ``` But mvc doesn't let me add two remote attributes. How could I solve that? Thanks for the help.