引导模态内部的表单提交将我重定向到查看页面

时间:2018-10-02 12:03:32

标签: asp.net-mvc modal-dialog

我有一个MVC项目。 首页/索引视图会在引导程序模式内加载 Users / Create 视图。但是我的<input type="submit" />将应用程序重定向到 Users / Create 视图的页面。我希望应用程序在打开模式的情况下使我保持在 Home / Index 上。我该怎么办?

这是我的 Users / Create (我的 Users / Create ),已加载到 Home / Index

@model Project.Models.User

@{
    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">CREATE USER</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.Name, new { @class = "txtB" })</div>
                @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
            </div>

            <div class="row">
                <div class="col col-12">E-mail: @Html.TextBoxFor(model => model.Email, new { @class = "txtB" })</div>
                @Html.ValidationMessageFor(model => model.Email, "", new { @class = "text-danger" })
            </div>

            <div class="row">
                <div class="col col-12">Password: @Html.PasswordFor(model => model.Passwd, new { @class = "txtB" })</div>
                @Html.ValidationMessageFor(model => model.Passwd, "", new { @class = "text-danger" })
            </div>

            <div class="row">
                <div class="col col-12">Confirm password: <input type="password" name="name" value="" class="txtB" /></div>
            </div>

            <div class="row">
                <div class="col col-12"><input type="submit" name="Create" value="Create" class="btn btn-primary" /></div>
            </div>

        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>

    </div>
</div>
}

这就是我在首页/索引上打开模式的方式:

<div class="modal fade" id="modal"></div>
<script>
    $(function () {
        $(".add-user").click(function () {
            $("#modal").load("../Users/Create", function () {
                $("#modal").modal();
            })
        });
    })
</script>

0 个答案:

没有答案