I have this AdvertiserNameAvailable
method that is being used by Remote validation attribute.
The problem is that the AdvertiserNameAvailable
is being called without passing the input value to the method Name
parameter. When I enter in debug into the method, I see that the Name
parameter is always null
.
public JsonResult AdvertiserNameAvailable(string Name)
{
return Json("Some custom error message", JsonRequestBehavior.AllowGet);
}
public class AdvertiserAccount
{
[Required]
[Remote("AdvertiserNameAvailable", "Accounts")]
public string Name
{
get;
set;
}
}
Had to add [Bind(Prefix = "account.Name")]
public ActionResult AdvertiserNameAvailable([Bind(Prefix = "account.Name")] String name)
{
if(name == "Q")
{
return Json(false, JsonRequestBehavior.AllowGet);
}
else
{
return Json(true, JsonRequestBehavior.AllowGet);
}
}
To find out your prefix, right click and do inspect element on the input that you are trying to validate. Look for the name
attribute:
<input ... id="account_Name" name="account.Name" type="text" value="">
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