1
I have an MVC project. A View Home/Index charges the View Usuarios/Create in the form of a bootstrap modal. However, my <input type="submit" />
redirects me to the view address Usuarios/Create. I wanted application to stay in View Home/Index with the modal open. How can I do this?
This is the code of my View Usuarios/Create which is carried as modal in Home/Index:
@model Project.Models.Usuario
@{
Layout = null;
ViewBag.Title = "Create";
}
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="modal-dialog modal-dialog-centered modal-md">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">CADASTRO</h4>
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
</div>
<div class="modal-body">
<div class="row">
<div class="col col-12">Seu nome: @Html.TextBoxFor(model => model.Nome, new { @class = "campo" })</div>
@Html.ValidationMessageFor(model => model.Nome, "", new { @class = "text-danger" })
</div>
<div class="row">
<div class="col col-12">Seu melhor email: @Html.TextBoxFor(model => model.Email, new { @class = "campo" })</div>
@Html.ValidationMessageFor(model => model.Email, "", new { @class = "text-danger" })
</div>
<div class="row">
<div class="col col-12">Defina sua senha: @Html.PasswordFor(model => model.Senha, new { @class = "campo" })</div>
@Html.ValidationMessageFor(model => model.Senha, "", new { @class = "text-danger" })
</div>
<div class="row">
<div class="col col-12">Digite a senha novamente: <input type="password" name="name" value="" class="campo" /></div>
</div>
<div class="row">
<div class="col col-12"><input type="submit" name="cadastrar" value="CADASTRAR" class="botao botao-principal" /></div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
</div>
</div>
</div>
}
And that’s how I open the modal in Home/Index:
<div class="modal fade" id="modal"></div>
<script>
$(function () {
$(".cadastrar").click(function () {
$("#modal").load("../Usuarios/Create", function () {
$("#modal").modal();
})
});
})
</script>
https://softdevpractice.com/blog/asp-net-core-mvc-ajax-modals/
– Roberto de Campos
Did some answer work John?
– novic