绑定preFIX远程验证行动没有奏效 [英] Bind Prefix not worked in Remote validation Action
本文介绍了绑定preFIX远程验证行动没有奏效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我问过类似的问题<一href="http://stackoverflow.com/questions/10562261/parameter-name-in-remote-model-validation-action-of-mvc3">here.这是我的模型:
I ask a similar question here. This is My Model:
[DisplayName("National Code")]
[Required(ErrorMessage = "Required")]
[RegularExpression(CustomRegex.SSNRX, ErrorMessage = CustomRegex.SSNErMsg)]
[Remote("DBValidateSSN", "CustomerProfile", "Members", ErrorMessage = "Repeated.")]
public string SSN { get; set; }
所以我用一个泛型类作为一个模型,我的看法是这样的:
So I use a Generic Class as a Model And My View is like:
@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参数总是空,哪里是我的错吗?有什么问题我也查的Ajax请求参数的萤火虫和使用的名称是 MainModel.SSN
,你有什么建议?
推荐答案
尝试这样的:
public ActionResult DBValidateSSN([Bind(Prefix = "MainModel.SSN")] string SSN)
{
// ...
return Json(result, JsonRequestBehavior.AllowGet);
}
这篇关于绑定preFIX远程验证行动没有奏效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文