我有这个AdvertiserNameAvailable
远程验证属性正在使用的方法。
问题是AdvertiserNameAvailable
正在调用而不将输入值传递给方法Name
范围。当我进入该方法的调试时,我看到Name
参数总是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;
}
}
必须添加[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);
}
}
要找出您的前缀,请右键单击并检查您要验证的输入上的元素。寻找name
属性:
<input ... id="account_Name" name="account.Name" type="text" value="">
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)