I am loading a Modal popup form using PartialView
The code
$("#modalContainer").load('@Url.Action("NewRefill","Car",new {car=@Model.Id})');
$.validator.unobtrusive.parse($("#modalContainer form"));
$("#addNewEntryModal").modal('show');
in my Controller I have
[HttpPost]
public ActionResult NewRefill(Car car,int car)
{
if (ModelState.IsValid)
{
}
return Json(new { Success = false });
}
This is a Modal popup. Every time You hit submit, it automatically forwards you to a new page. What I would like it to do would be to Keep the Modal open and show the Errors that happen. I have tried binding to the Submit event and stopping it to no avail. The validations do work since I see the Red borders but I get forwarded and see the Success=false
You are not parsing the jQuery unobtrusive validations at the right place. You should do that once you load the partial, inside the success callback:
Also if inside this partial you are using an
Ajax.BeginFormhelper to generate the form make sure that you have included thejQuery.unobtrusive-ajax.jsscript to your page for this to work. And if it is a normalHtml.BeginFormyou should AJAXify it if you want it to be submitted with an AJAX request instead of a normal request: