提交表单后,在mvc asp.net中打开一个弹出窗口

时间:2018-06-25 09:12:13

标签: asp.net asp.net-mvc

提交后,我无法打开模式窗口。我到目前为止所拥有的是: 这是我正在调用的View Permitions.cshtml 在控制器Admin中提交操作SalvarPermissoes

@using (Html.BeginForm("SalvarPermissoes", "Admin", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
    {
        <header>
            <h2 id="titulo" name="titulo">@ViewBag.Title  | @ViewBag.UserPrincipal.Name | @ViewBag.UserPrincipal.EmployeeId </h2>
        </header>
        <input name="permissoes_modulos" hidden value="@ViewBag.UserPrincipal.EmployeeId" />
        <table>
            @foreach (var mod in ViewBag.Modulos)
            {
                <tr>
                    <td><label name="permissoes_modulos" value="@mod.moduloId">@mod.moduloId</label></td>
                    <td><label>@mod.nomeModulo</label></td>
                    <td>
                        <div class="form-check">
                            <label class="switch">
                                @if (mod.acesso == 1)
                                {
                                    <input name="permissoes_modulos" type="checkbox" checked data-toggle="toggle" id="@mod.moduloId" value="@mod.moduloId"/>
                                }
                                else
                                {
                                    <input name="permissoes_modulos" type="checkbox" data-toggle="toggle" id="@mod.moduloId" value="@mod.moduloId"/>
                                }
                                <span class="slider round"></span>
                            </label>
                        </div>
                    </td>
                </tr>
            }
        </table>
        <div class="col-md-offset-2 col-md-10">
            <input type="submit" class="btn btn-default" value="salvar" />
        </div>
    }

然后我的管理控制器执行操作SalvarPermissoes

public ActionResult SalvarPermissoes(int[] permissoes_modulos)
{
    int employeeID = permissoes_modulos[0];

    UserManagement userManagement = new UserManagement();
    userManagement.EmployeeID = employeeID;
    userManagement.DeleteUserManagement();

    for(int i = 1; i < permissoes_modulos.Length; i++)
    {
        userManagement.ModuleID = permissoes_modulos[i];
        userManagement.InsertUserManagement();
    }

    return View(); //this target view is suppose to be a modal window
}

此控制器称为视图SalvarPermissoes.cshtml,我希望它是优先使用引导程序的模式窗口。

预先感谢

1 个答案:

答案 0 :(得分:0)

您可以使用viewBag从控制器发送消息以进行查看。 由于ViewBag.Msg被检查为空,因此只有在初始化insde SalvarPermissoes操作之后,才会弹出消息。

public ActionResult SalvarPermissoes(int[] permissoes_modulos)
{
 int employeeID = permissoes_modulos[0];

UserManagement userManagement = new UserManagement();
userManagement.EmployeeID = employeeID;
userManagement.DeleteUserManagement();

for(int i = 1; i < permissoes_modulos.Length; i++)
{
    userManagement.ModuleID = permissoes_modulos[i];
    userManagement.InsertUserManagement();
}
ViewBag.Msg = "Thankyou for submitting form";
return View(); //this target view is suppose to be a modal window
}

查看

将其放在视图顶部

@if (ViewBag.Msg != null)
{

    <!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Post Status</h4>
            </div>
            <div class="modal-body">
                <p >@ViewBag.Msg.</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

<button type="button" class="btn btn-info btn-lg" id="bootstrapmodel" data-toggle="modal" data-target="#myModal" style="display:none">Open Small Modal</button>
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

    <script>

    $('#myModal').modal('show');
    </script>
}