MVC4 Default route when using areas

前端 未结 8 1424
灰色年华
灰色年华 2021-02-03 12:30

I\'m trying to use areas within MVC app, I would like that the default route will be resolved to the HomeController within the admin area but it resolves to the home controller

8条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-03 13:12

    The most straightforward way is to add a data token to your default route:

    routes.MapRoute(
        "Default",
        "{controller}/{action}/{id}",
        new {controller = "Home", action = "Index", id = UrlParameter.Optional }
    ).DataTokens.Add("area", "Admin");
    

    Simply add

    .DataTokens.Add("area", "[your area name]");
    

    to the end of your default route definition.

提交回复
热议问题