c# - Call ActionResult in the Area controller from a shared view -


from layout.cshtml inside views folder (outside areas), need resolve action method of controller created inside area.

i have few custom routes defined, default route always:

routes.maproute("default", "{controller}/{action}/{id}",                new { controller = "home", action = "index", id = urlparameter.optional }); 

eg:

area - test, controller - homecontroller, action method - index

@url.action("index", "home", new { area = "test" }) returns empty string. @html.actionlink("test link", "index", "home") returns empty string.

@html.routelink("test link", "default", new { controller = "home", action = "index" }) returns in error

a route named 'default' not found in route collection.

just clarify, action doesn't need invoked using custom route. never directly accessible via url, default route should fine.

i bummed. how can resolve action?

under same namespace add following class

public class testarearegistration : arearegistration {     public override string areaname     {                 {             return "test";         }     }      public override void registerarea(arearegistrationcontext context)     {         context.maproute(             "test_default",             "test/{controller}/{action}/{id}",             new { action = "index", id = urlparameter.optional }         );     } } 

under global.asax make sure have registerallareas()

protected void application_start()     {         arearegistration.registerallareas();                 } 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -