Calling a Modal via Html.ActionLink

0

I have a screen that does the user's password change. This screen shows the user name and clicking the name, it is directed to the screen to change the password.

As I would do to make this call with a modal, I already have the scripts, but I can not use it with Html.ActionLink

@using Microsoft.AspNet.Identity

@if (Request.IsAuthenticated)
{
    using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" }))
    {
        @Html.AntiForgeryToken()
        @Html.ActionLink("Hello " + User.Identity.GetUserName() + "!", "ChangePassword", "Manage" ))
    }
}

<script type="text/javascript">

        $(function () {
            $.ajaxSetup({ cache: false });   
            $("a[data-modal]").on("click", function (e) {
                $('#myModalContent1').load(this.href, function () {
                    $('#myModalLogin').modal({
                        /*backdrop: 'static',*/
                        keyboard: true
                    }, 'show');
                    bindForm(this);
                });
                return false;
            });
        });

        function bindForm(dialog) {
            $('form', dialog).submit(function () {
                $.ajax({
                    url: this.action,
                    type: this.method,
                    data: $(this).serialize(),
                    success: function (result) {
                        if (result.success) {
                            $('#myModalLogin').modal('hide');
                            $('#replacetarget').load(result.url); // Carrega o resultado HTML para a div demarcada
                        } else {
                            $('#myModalContent1').html(result);
                            bindForm(dialog);
                        }
                    }
                });
                return false;
            });
        }
    </script>

<div id="myModalLogin" class="modal fade in">
    <div class="modal-dialog">
        <div class="modal-content">
            <div id="myModalContent1"></div>
        </div>
    </div>
</div>
    
asked by anonymous 30.11.2018 / 16:43

1 answer

0

I recommend you call an Action in your controller through a .js method where it will return your View () with your model:

public ActionResult RetornarModal()
{
  return PartialView("_Partial", model);
}

And in the success of the request you continue doing the same thing, feeding .html() to the result of the request.

Set the onClick() event of the link to your new method by doing the request.

    
03.12.2018 / 10:57