Return Partialview with validations for a Modal ASP MVC 4

Asked

Viewed 454 times

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) this way:

<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 like this:

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

, but it returns only partial without style or script at all, instead of returning this partial into Modal, someone knows how to return the partial content into the modal with the validations made on the server?

  • Thiago are you using ajax? What you want is to load this content without refreshing the right page? Take a look here: http://answall.com/a/6634/129

1 answer

1

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.