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.
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With