Bind prefix does not work in Remote validation action

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; } 

Therefore, I use the generic class as a model, and my view looks like this:

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

And confirm the action:

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

But the SSN parameter in action is always zero, where is my error? what is the problem, I also check Ajax Request Params in FireBug and used name MainModel.SSN , what is your suggestion?

+1
source share
1 answer

Try it like this:

 public ActionResult DBValidateSSN([Bind(Prefix = "MainModel.SSN")] string SSN) { // ... return Json(result, JsonRequestBehavior.AllowGet); } 
+1
source

Source: https://habr.com/ru/post/1412126/


All Articles