ASP.NET MVC `Html.ActionLink` between “Areas”

后端 未结 6 549
灰色年华
灰色年华 2021-01-31 01:58

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\'.<

6条回答
  •  太阳男子
    2021-01-31 02:49

    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.

    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);
            }
    

    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!

提交回复
热议问题