Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parameter Name in Remote Model Validation Action of MVC3

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)

and My Action is:

public JsonResult IsValidaSSN(string SSN) {

  //....

    return Json(result, JsonRequestBehavior.AllowGet);

}

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?

like image 264
Saeid Avatar asked Dec 20 '22 22:12

Saeid


1 Answers

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.

like image 133
Darin Dimitrov Avatar answered Jan 08 '23 04:01

Darin Dimitrov