Click here to Skip to main content
15,905,877 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am working for a MVC 5 application, in which i have the main application, and there is two Area(Admin,Billing) in same application. there is HomeController in Main application, Admin Area and Billing Area. i have set the default route for Billing Area Billcontroller in main application RouteConfig.cs file: see below:
public static void RegisterRoutes(RouteCollection routes)
      {
          routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

          //routes.MapRoute(
          //    name: "Default",
          //    url: "{controller}/{action}/{id}",
          //    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
          //    namespaces: new string[] { "MvcAreaDemoApp.Controllers" }
          //);

          routes.MapRoute(
             name: "Default",
             url: "{controller}/{action}/{id}",
             defaults: new { controller = "Bill", action = "Index", id = UrlParameter.Optional }
          , namespaces: new string[] { "MvcAreaDemoApp.Controllers" }
         ).DataTokens["area"] = "Billing";
      }

When i am trying to go in main application Home controller method, i not redirecting to home controller for main application, it's going to same areas homecontroller method.

What I have tried:

<a href="@Url.Action("Index","Home", new { area="" })">Dashboard</a>
Posted
Updated 28-Aug-18 3:03am

1 solution

I don't think you need the "new {area = ""}" segment
so just,
C#
<a href="@Url.Action("Index","Home")">Dashboard</a>

if you are using areas then you need to use something like
@Url.Action("Method", "Controller", new {Area = "AreaName"})

when you load the page up you can always check where the url is pointing to by using the browser's developer tools. eg on chrome right click inspect
If the URL is as you are expecting and it is still not working then it is probably your routing that is wrong. Mine looks like this
routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
 
Share this answer
 
v2
Comments
Member 10371658 28-Aug-18 13:08pm    
it's not working for main application, it's going for Index method of Billing area HomeController method.
Richard Maly 29-Aug-18 2:15am    
In which case you do need the area part, but enter the name of the area in, rather than the empty quotes. The area is the folder name
Member 10371658 6-Sep-18 14:11pm    
i want to go out side of the area, mean main application, i have main application in which i have the two area, and i have set the default route for area controller in main application routeconfig.cs file.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900