1

ここで同様の質問をします。これは私のモデルです:

[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 パラメータは常に null です。どこに問題があるのでしょうか? FireBug で Ajax Request Params もチェックしていますがMainModel.SSN、使用されている名前は です。あなたの提案は何ですか?

4

1 に答える 1

2

このようにしてみてください:

public ActionResult DBValidateSSN([Bind(Prefix = "MainModel.SSN")] string SSN)
{
    // ...
    return Json(result, JsonRequestBehavior.AllowGet);
}
于 2012-05-12T12:20:33.100 に答える