Return PartialView with validations for an ASP Modal MVC 4

4

I have an Index screen, where is the table of registered people, on the same screen I have a new button that calls a Modal (boostrap) like this:

<a href="@Url.Action("Add", "Pessoa", new { area = "Gestor" })" class="btn btn-primary" data-toggle="modal" data-target="#modalPessoa">
    <span class="glyphicon glyphicon-plus"></span> Novo
</a>

and the controller returns return PartialView("Partial/ModalPessoa");

The content of ModalPessoa is a form with several fields that are mandatory, when it is given submit goes to the controller that is this way:

if (ModelState.IsValid)
{
    return RedirectToAction("Index");
}
return PartialView("Partial/ModalPessoa", model);

, but it returns only the partial without style or script none, instead of returning this partial into Modal, does anyone know how to return the contents of the partial into the modal with the validations done on the server?

    
asked by anonymous 21.05.2015 / 02:01

1 answer

1

If the idea is to bring a Modal to register new records, using Partials interacting with the Controller is unnecessary. As a good practice, Modal can be hidden and displayed through a simple JS event.

To display validation in case of errors, there are three alternatives:

23.08.2016 / 17:16