Open page in modal form

Asked

Viewed 333 times

3

I’m doing a crud and would like to open another page in modal form, but do not know how to do this, I even found on a site explaining how to do with javascript but when clicking the button nothing happens. Could anyone help me? On the Index page I wanted to open the Create page in modal form.

Página Index:

@{
    ViewBag.Title = "Index";
}

<div class="p-3 mb-2 bg-light text-dark">
    <div class="row">
        <div class="col-8"><h3>Index</h3></div>
            <div class="col-4">
                <button type="button"
                    onclick="criar()"/>
            @Html.ActionLink("+", "Create")
        </div>
    </div>
</div>

@{

    <script>
        function criar() {
            $("#modalCreate").load("/Pracas/Create", function () {
                $("#modalCreate").show();
            });
        }
    </script>
}

Página Create:

@{
    ViewBag.Title = "Create";
}


@using (Html.BeginForm()) 
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <h4>Create</h4>

        texto
    </div>
}

Thank you.

  • 1

    Also put your Javascript code to make it clearer what you’re trying to do

  • Maycon, I added the javascript that was missing!

2 answers

3


I made on a page, I also had the same doubt but! the answer is quite simple.

In the event of the button and only by the following code,

System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "_new", "window.open('paginaCreate .aspx?modo=consultar','','toolbar=no,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,fullscreen=yes');", true);
  • Okay, thank you for the reply Wallafe!

0

Try putting a @Html.Partial("modal name") to load your html code on the index page. It would look something like this:

Página Index:

@{
    ViewBag.Title = "Index";
}

  @Html.Partial("_Create") @*coloque o nome da sua página modal aqui*@

<div class="p-3 mb-2 bg-light text-dark">
    <div class="row">
        <div class="col-8"><h3>Index</h3></div>
            <div class="col-4">
                <button type="button"
                    onclick="criar()"/>
            @Html.ActionLink("+", "Create")
        </div>
    </div>
</div>

@{

    <script>
        function criar() {
            $("#modalCreate").load("/Pracas/Create", function () {
                $("#modalCreate").show();
            });
        }
    </script>
}

Página Create:

@{
    ViewBag.Title = "Create";
}


@using (Html.BeginForm()) 
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <h4>Create</h4>

        texto
    </div>
}

Browser other questions tagged

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