Parameter Name in Remote Model Validation Action of MVC3

淺唱寂寞╮ 提交于 2019-12-03 08:36:58

You could try specifying a prefix:

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

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

Another, slightly more precise, take on Rahul's answer:

public JsonResult IsValidImageUrl(string SSN) {
    if (string.IsNullOrEmpty(SSN)) {
        string parmname = Request.QueryString.AllKeys.FirstOrDefault(k => k.EndsWith(".SSN"));
        if (!string.IsNullOrEmpty(parmname)) {
            SSN = Request.QueryString[parmname];
        }
    }

    //.... etc.

This can fly with multiple parameters.

Side note, you probably want to reconsider the association of a "GET" JSON method with anything associated with SSN's.

I resolved this issue by just using the first query string parameter:

public JsonResult IsValidImageUrl(string value) {

    if (value == null && Request.QueryString.Count == 1) {
            value = Request.QueryString[0];
        }


    //....            

    return Json(result, JsonRequestBehavior.AllowGet);                    
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!