在MVC3的遥控模型验证动作参数名称 [英] Parameter Name in Remote Model Validation Action of MVC3

查看:154
本文介绍了在MVC3的遥控模型验证动作参数名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用远程验证属性, SSN 属性,在视图我使用通用视图然后SSN字段是这样的:

I use Remote validation attribute for SSN property, In view Page I use generic view then the ssn field is like:

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

和我的动作是:

public JsonResult IsValidaSSN(string SSN) {

  //....

    return Json(result, JsonRequestBehavior.AllowGet);

}

但总是 SSN 是动作空,我也尝试 MainModelSSN MainModel_SSN ,但没有改变,总是为空,你有什么建议吗?什么是 MainModel.SSN 在操作参数的正确名称?

but always SSN is null in action, I also try MainModelSSN, MainModel_SSN but no change and always is null, what is your suggestion? what is the correct name for MainModel.SSN in action argument?

推荐答案

您可以尝试指定preFIX:

You could try specifying a prefix:

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

MainModel 是用于发送数据preFIX => MainModel.SSN

MainModel is the prefix that is used to send the data => MainModel.SSN.

这篇关于在MVC3的遥控模型验证动作参数名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆