Scoped MVC - Html.ActionLink returns invalid URL / route?

I am using MVC3 and have Scopes in my application. In general, everything works fine, I can go to my area (for example, Admin = Area, Controller = Department) as follows:

<%: Html.ActionLink("Departments", "DepartmentIndex", "Department", new { area = "Admin"}, null )%> 

However, I noticed that if I do not specify the scope in my ActionLink, for example.

 <%: Html.ActionLink("Test", "Index", "Home")%> 

This will stop working if I go to the admin area. i.e. my url is now http: // localhost / myproj / Admin / Home / Index instead of http: // localhost / myproj / Home / Index

Any ideas on what's going on here?

My routes are all default values ​​when creating the application / MVC areas. i.e.

  public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional }, new[] { "MyProj.Controllers" } ); } 

And my area registration

  public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute( "Admin_default", "Admin/{controller}/{action}/{id}", new { action = "Index", id = UrlParameter.Optional } ); } 

Is it for design? This post suggests using RouteLink instead of ActionLink: say, using RouteLink Do I need to have an "area" routevalue in the actionlink if the application was grouped into areas?

+6
source share
1 answer

fooobar.com/questions/578822 / ... it is correctly indicated that you need to specify the name Area if you use areas.

eg.

 Html.ActionLink("Home", "Index", "Home", new { Area = "" }, new { }) 
+7
source

Source: https://habr.com/ru/post/889057/


All Articles