ASP.NET MVC Remote属性方法参数始终传递null

use*_*812 5 asp.net-mvc asp.net-mvc-3

我有AdvertiserNameAvailable远程验证属性使用的此方法.问题是在AdvertiserNameAvailable没有将输入值传递给方法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;
      }
  }
Run Code Online (Sandbox Code Playgroud)

use*_*812 13

不得不补充一下 [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);
    }
}
Run Code Online (Sandbox Code Playgroud)

要找出您的前缀,请右键单击并检查您要验证的输入上的元素.寻找name属性:

<input ... id="account_Name" name="account.Name" type="text" value="">
Run Code Online (Sandbox Code Playgroud)