2

我试图让这个http://blog.stevehorn.cc/2009/06/rendering-modal-dialog-with-aspnet-mvc.html与 MVC 3 一起工作。

我是 ASP.Net MVC 的新手,最近开始了一个 MVC 3 项目。当用户单击我的 _Layout.cshtml 文件中的登录超链接时,我想显示一个模式登录表单:

<a href="#" id="LogIn">Log In</a>

我在以下位置创建了一个登录视图 Areas/Auth/Views/Auth/Login.cshtml

我已将以下脚本添加到我的 _Layout.cshtml 文件中:

    <script type="text/javascript">
        $(document).ready(function () 
        {
            $("#LogIn").click(function (event) 
            {
                $.get( 
                      "~/Areas/Auth/Views/Auth/Login" ,
                      function (htmlResult) 
                      {
                        $("#LoginModal").remove(); //In case this is the second time they've requested the dialog.
                        $("#container").append(htmlResult);
                        $("#LoginModal").dialog();
                      }
                    );
            return false; //To keep the default behavior of the anchor tag from occuring.
});                
</script>

并向我的 AuthController 添加了 PartialViewResult:

        public PartialViewResult LoginView()
    {
        return PartialView("Login");
    }

但是,单击登录链接时没有任何反应。任何关于这样做的好的 MVC 3 教程的建议或链接,将不胜感激。

谢谢!

4

1 回答 1

1

您的 URI 错误:

"~/Areas/Auth/Views/Auth/Login"

这是对视图的引用,而不是操作。您的 URI 需要引用一个操作。此外,JavaScript 无法理解 ASP.NET 的~语法。你可能想要类似的东西<%: Url.Content("~/Auth/Auth/LoginView") %>

将来,调试这些东西的好方法是 Firebug 的网络面板或 Fiddler。您应该会看到 AJAX 调用返回 404。

于 2011-02-15T14:34:29.550 回答