Open modal popup in another .cshtml file

2

File.cshtml is found 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>

As I'm working with ASP.NET MVC, when I write: url: "'/Usuario/arquivoFilho'," in method $ajax() , I'm saying that I have a user name controller and inside it an Action (function / method) as follows:

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

This action arquivoFilho() , redirects by default to the view "File.Cshtml" (This redirection happens because I created the view from the method), which has the content that I want to display in the popup. The file "File.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 is not working.

    
asked by anonymous 17.10.2014 / 14:18

1 answer

1

Michell, if you call the URL / User / FileFeed directly in the browser works? If so, I imagine the problem might be in your View because it returns a full HTML that is later included inside an HTML container (DIV). Since you are trying to include the complete content (which has the HTML tag) HTML formatting errors may 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>
}
    
07.11.2014 / 13:39