ASP.NET MVC`Html.ActionLink`&QUOT之间,区与QUOT; [英] ASP.NET MVC `Html.ActionLink` between "Areas"

查看:289
本文介绍了ASP.NET MVC`Html.ActionLink`&QUOT之间,区与QUOT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了一个新的领域,以我的MVC3项目,我试图从_layout页面链接到新的领域。我已经加入所谓的管理员,有一个控制器'会见'。一个区域

I have added a new Area to my MVC3 project and I am trying to link from the _Layout page to the new Area. I have added an Area called 'Admin' that has a controller 'Meets'.

我用Visual Studio设计添加的区域,以便它具有正确的区域注册类等,Global.asax文件正在注册的所有领域。

I used the visual studio designer to add the area so it has the correct area registration class etc, and the global.asax file is registering all areas.

然而,当我用以下2操作链接在根的页面时,我遇到了几个问题:

However, when I use the following 2 action links in a page in the root, I run into a few problems:

@Html.ActionLink("Admin", "Index", "Meets", new { area = "Admin" }, null)
@Html.ActionLink("Admin", "Index", "Meets", new { area = "" }, null)

当点击这两个链接,我采取了在管理区,那里的应用程序就继续抛出一个错误说,它不能找到索引页(即使索引页面在浏览present的会见控制器文件夹中的区域子目录

When clicking both links, I am taken to the Meets controller in the Admin area, where the application then proceeds to throw an error saying it cannot find the Index page (even though the Index page is present in the Views folder in the Area sub-directory.

为第一链接中的href看起来是这样的:

The href for the 1st link looks like this:

的http://本地主机/ BCC /会见面积=管理

而对于第二个链接中的href看起来是这样的:

And the href for the 2nd link looks like this:

的http://本地主机/ BCC /符合

另外,如果我打,我​​想到要创建的链接:

Also if I hit the link that I expect to be created:

的http://本地主机/ BCC /行政/符合

我刚刚得到的资源无法找到错误。一切都非常令人费解!我希望有人能够帮助...

I just get a resource cannot be found error. All very perplexing! I hope someone can help...

推荐答案

我想通了这一点 - 我创建了一个新的测试项目,并确实做到了,我之前做同样的事情和它的工作...那么毕竟进一步检查我发现了一个矛盾的两个项目之间的事情路线有关。

I figured this out - I created a new test project and did exactly the same thing I was doing before and it worked...then after further inspection of all things route-related between the two projects I found a discrepancy.

在我的BCC应用程序Global.asax文件中,有code的流氓线,已经莫名其妙地出现了:

In the global.asax file in my BCC application, there was a rogue line of code which had inexplicably appeared:

        public static void RegisterRoutes(RouteCollection routes)
        {
            // Problem here
            routes.Clear();

            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );
        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }

正如你可以看到我的意见是,在一段时间或其他我已经放在routes.Clear()调用时的RegisterRoutes的开始,这意味着我已经注册的Application_Start的地区后,我随后立即清理什么我刚刚注册的。

As you can see where my comment is, at some time or other I had placed the routes.Clear() call at the beginning of RegisterRoutes, which meant after I had registered the Areas in Application_Start, I was then immediately clearing what I had just registered.

感谢您的帮助......它并最终导致我的拯救!

Thanks for the help...it did ultimately lead to my salvation!

这篇关于ASP.NET MVC`Html.ActionLink`&QUOT之间,区与QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆