asp.net mvc - @Html.ActionLink is not linking to current area by default -


i have 2 areas admin , frontend (in order).

when in view in frontend area, actionlink points admin area:

@html.actionlink("checkout", "address", "checkout") 

will http://localhost:53600/admin/checkout/address checkout controller in frontend area.

i know can solve specifying routedata object in action link , setting area = "frontend" don't want to. want actionlink helper default current route.

is possible?

all questions i've read on actionlink people asking how link area indicates defaults current area them. alone issue?

edit, these routes can see tied correct namespace:

admin

public void registerroutes(routecollection routes) {     routes.maproute(         "administration_default",         "admin/{controller}/{action}/{id}",         new { controller = "home", action = "index", area = "administration", id = urlparameter.optional },         new[] { "cc.web.areas.administration.controllers" }         ); } 

frontend

public void registerroutes(routecollection routes) {     routes.maproute("default",         "{controller}/{action}/{id}",         new {controller = "home", action = "index", area = "frontend", id = urlparameter.optional},         new[] {"cc.web.areas.frontend.controllers"}         ); } 

areas should registered in classes deriving arearegistration overriding method void registerarea(arearegistrationcontext context), see msdn.

the arearegistrationcontext defines own methods register area routes add required datatokens areas used when generating links , urls:

public route maproute(string name, string url, object defaults, object constraints, string[] namespaces) {     if (namespaces == null && namespaces != null)     {         namespaces = namespaces.toarray();     }      route route = routes.maproute(name, url, defaults, constraints, namespaces);     route.datatokens[routedatatokenkeys.area] = areaname;      // disabling namespace lookup fallback mechanism keeps areas accidentally picking     // controllers belonging other areas     bool usenamespacefallback = (namespaces == null || namespaces.length == 0);     route.datatokens[routedatatokenkeys.usenamespacefallback] = usenamespacefallback;      return route; } 

it looks frontend shouldn't area, have standard mvc controllers , views (instead of fronteand area) admin area:

public class adminarearegistration : arearegistration {     public override string areaname     {                 {             return "administration";         }     }      public override void registerarea(arearegistrationcontext context)     {         context.maproute(             "administration_default",             "admin/{controller}/{action}/{id}",             new { controller = "home", action = "index", id = urlparameter.optional },             new[] { "cc.web.areas.administration.controllers" }         );     } } 

remember should calling arearegistration.registerallareas(); @ beggining of main registerroutes method invoked on app start.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -