Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc ASP.NET MVC远程属性方法参数始终传递null_Asp.net Mvc_Asp.net Mvc 3 - Fatal编程技术网

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;
      }
  }