Open modal popup in another . cshtml file

Asked

Viewed 1,127 times

2

Arquivopai.cshtml is as follows:

<html>
<head></head>
<body>
    <!-- Nesta div pretendo abrir minha popup -->
    <div id="popup"></div>

    <!-- Com este link pretendo acionar a abertura da popup -->
    <a id="open">Abrir PopUp</a>

    <script type="text/javascript">
        $("#open").click(function () {
            $.ajax({
                type: 'GET',
                url: '/Usuario/arquivoFilho',
                success: function (data) {
                    $('#popup').html(data);
                    $('#popup').show();
                }
            });
        });
    </script>
</body>
</html>

How I’m working with ASP.NET MVC, when I write: url: "'/Usuario/arquivoFilho'," in the method $ajax(), I am saying that I have a controller named user and inside it an Action (function/method) called fileFile, which is found as follows:

namespace WebApplication1.Controllers
{
    public class UsuarioController : Controller
    {
        public ActionResult arquivoFilho()
        {
            return View();
        }
    }
}

This action arquivoFilho(), redirects by default to the "fileFile.cshtml" view (This redirect happens because I created the view from the method), which has the content I intend to display in the popup. The file "filename.cshtml" is found as follows:

<html>
<head></head>
<body>
<h2>Editar Usuário</h2>
    @using (Html.BeginForm("Index", "Usuario", new { ReturnUrl = ViewBag.ReturnUrl }, 
        FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
    {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary(true)
        @Html.HiddenFor(x => x.login)
        <div class="editor-label">
            @Html.LabelFor(model => model.login)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.login)
            @Html.ValidationMessageFor(model => model.login)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.senha)
        </div>
        <div class="editor-label">
            @Html.EditorFor(model => model.senha)
            @Html.ValidationMessageFor(model => model.senha)
        </div>
        <p><input type="submit" value="Save" /></p>
    }
</body>
</html>

The fact is that it’s not working.

  • 4

    put more details so that we can understand if any javascript error is occurring or in your Editusuario action

  • Blz Tiago Silva, I’ll try Alert().

  • I just did a reprint of my problem with a little more detail.

  • Hi, Michell, welcome to [en.so]. Formatting here is with Markdown, check out the guide: http://answall.com/editing-help

1 answer

1

Michell, if you call the URL /User/Filename directly in the browser works? If so, I imagine the problem may be in your View, because it returns a complete HTML that is later included within a container (DIV) HTML. As you are trying to include the full content (which has the HTML tag) HTML formatting errors can occur. I suggest you change your VIEW as follows:

<h2>Editar Usuário</h2>
@using (Html.BeginForm("Index", "Usuario", new { ReturnUrl = ViewBag.ReturnUrl }, 
    FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)
    @Html.HiddenFor(x => x.login)
    <div class="editor-label">
        @Html.LabelFor(model => model.login)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.login)
        @Html.ValidationMessageFor(model => model.login)
    </div>
    <div class="editor-label">
        @Html.LabelFor(model => model.senha)
    </div>
    <div class="editor-label">
        @Html.EditorFor(model => model.senha)
        @Html.ValidationMessageFor(model => model.senha)
    </div>
    <p><input type="submit" value="Save" /></p>
}

Browser other questions tagged

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