【问题标题】:Bind Prefix not worked in Remote validation Action绑定前缀在远程验证操作中不起作用
【发布时间】:2012-05-20 17:25:39
【问题描述】:

我问了一个类似的问题here。这是我的模特:

[DisplayName("National Code")]
[Required(ErrorMessage = "Required")]
[RegularExpression(CustomRegex.SSNRX, ErrorMessage = CustomRegex.SSNErMsg)]
[Remote("DBValidateSSN", "CustomerProfile", "Members", ErrorMessage = "Repeated.")]
public string SSN { get; set; }

所以我使用泛型类作为模型,我的视图是这样的:

@Html.EditorFor(model => model.MainModel.SSN)
@Html.ValidationMessageFor(model => model.MainModel.SSN)

并验证操作:

public JsonResult DBValidateSSN([Bind(Prefix = "MainModel")] string SSN) {

  // ....
  return Json(result, JsonRequestBehavior.AllowGet);
}

但是SSN参数在行动中总是为空,我的错在哪里?什么问题我也在 FireBug 中检查了 Ajax 请求参数,使用的名称是 MainModel.SSN,你有什么建议?

【问题讨论】:

    标签: ajax asp.net-mvc asp.net-mvc-3 validation


    【解决方案1】:

    试试这样:

    public ActionResult DBValidateSSN([Bind(Prefix = "MainModel.SSN")] string SSN)
    {
        // ...
        return Json(result, JsonRequestBehavior.AllowGet);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-12
      • 1970-01-01
      • 2015-03-17
      • 1970-01-01
      • 2010-11-17
      • 2019-07-17
      • 1970-01-01
      相关资源
      最近更新 更多