Asp.net mvc ASP.NET MVC远程属性方法参数始终传递null
我有一个可用的Asp.net mvc ASP.NET MVC远程属性方法参数始终传递null,asp.net-mvc,asp.net-mvc-3,Asp.net Mvc,Asp.net Mvc 3,我有一个可用的广告商名称方法,远程验证属性正在使用该方法。 问题是调用的advertizernameavable没有将输入值传递给方法Name参数。当我在方法中输入debug时,我看到Name参数总是null public JsonResult AdvertiserNameAvailable(string Name) { return Json("Some custom error message", JsonRequestBehavior.AllowGet); }
广告商名称
方法,远程验证属性正在使用该方法。
问题是调用的advertizernameavable
没有将输入值传递给方法Name
参数。当我在方法中输入debug时,我看到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”)]
要查找前缀,请右键单击并检查您尝试验证的输入上的元素。查找名称
属性:
<input ... id="account_Name" name="account.Name" type="text" value="">
还应注意:
需要OutputCacheAttribute属性以防止
NET MVC缓存验证方法的结果
因此,在控制器操作中使用[OutputCache(Location=OutputCacheLocation.None,NoStore=true)]
<input ... id="account_Name" name="account.Name" type="text" value="">
[HttpPost]
[OutputCache(Location = OutputCacheLocation.None, NoStore = true)]
public ActionResult AdvertiserNameAvailable(string Name)
{
bool isNameAvailable = CheckName(Name); //validate Name and return true of false
return Json(isNameAvailable );
}
public class AdvertiserAccount
{
[Required]
[Remote("AdvertiserNameAvailable", "Accounts", HttpMethod="Post", ErrorMessage = "Some custom error message.")]
public string Name
{
get;
set;
}
}