简体   繁体   中英

open a popup window in mvc asp.net after submitting a form

i am not able to open a modal window after submitting. What i have so far is this : this is my View Permitions.cshtml that is calling that is submiting to Action SalvarPermissoes In controller Admin

@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>
    }

then my Admin Controller have the action 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
}

and this controller is call a view SalvarPermissoes.cshtml which i want to be a modal window using preferentially bootstrap.

Thanks in advance

You can use viewBag for sending message from controller to view. Since ViewBag.Msg is checked for null it will popup the message only after initialize insde SalvarPermissoes action.

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
}

View

put this inside top of view

@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>
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM