How to call an Html.Action("my page") via jquery?

Asked

Viewed 1,031 times

0

I have a page that loads several partials views, I want to call in a modal a specific page that will fill the entire screen. I am using a generic jquery command to call an action that will be passed by parameters.

This is the button

<button type="button" class="btn glyphicon glyphicon-zoom-in loopa" data-id="_ArquivosProcDia"></button>

This is the div

<div class="modal fade" id="modal4" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
            </div>
            <div class="modal-body" id="abrezoompagina">
                @Html.Action("_ArquivosProcDia")
            </div>
        </div>
    </div>
</div>

This is the script

<script>
$(".loopa").click(function () {
    var part = $(this).attr("data-id");
    var part2 = $(this).replaceWith(@(Html.Action(part));
    $("#modal4").modal();
});

Each partial view will have its own magnifying glass to bring the modal with its information, the partial that will be opened in this example will be the _Archivosprocdia.

  • I did not understand very well what your doubt is. I could explain a little more?

  • Yes of course, well I would like to create a generic script to call several partials that are in the main index. I load partial via Razor, but @Html.Action ("partial_view") cannot be entered in jquery because it loads the content there. I want to see if it is possible to call these partial in order to use only one script, passing the partial parameters by the button data-id.

2 answers

2


I don’t really understand what your code does, but in my systems I usually graft modal into HTML like this:

        <script type="text/javascript">
            $("#meu-botao").click(function () {
                $.get(@Url.Action("_ArquivosProcDia"), function (template) {
                    $("#alguma-div").append(template);
                    // Aqui coloco um código pra chamar a Modal.
                });
            });
        </script>

Anyway, your code won’t work. To work, it would have to be something like this:

$(".loopa").click(function () {
    var part = $(this).attr("data-id");
    var part2 = $(this).replaceWith(@Url.Action(part));
    $("#modal4").modal();
});

0

I had to do so to work, but I’ll have to repeat for each modal.

<script type="text/javascript">
$(".loopa").click(function () {
    var part = $(this).attr("data-id");
    $.get("@(Html.Raw(Url.Action("_ArquivosProcDia", "Home")))", function (template) {
        $("#abrezoompagina").replaceWith(template);
        $("#modal4").modal();
    });
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.