我正在努力得到这个 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>

并将 PartialViewResult 添加到我的 AuthController 中:

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

但是,单击登录链接时没有任何反应。任何有关执行此操作的建议或指向良好 MVC 3 教程的链接,我们将不胜感激。

谢谢!

有帮助吗?

解决方案

您的 URI 错误:

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

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

将来调试这些东西的一个好方法是Firebug的net panel或者Fiddler。您应该看到 AJAX 调用返回 404。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top