I have an MVC project. A View Home / Index loads View Users / Create as a bootstrap modal. However, my <input type="submit" />
redirects me to the Users / Create view address. I wanted the application to remain in the View Home / Index with the modal open. How can I do this?
This is the code for my View Users / Create that is loaded 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 this is 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>