MVC4 Default route when using areas

前端 未结 8 1622
灰色年华
灰色年华 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:07

    Try doing this way....it will help in distinguish.Even if you dont add area="Web", its fine

    routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters
        new { controller = "Home", action = "Index", area="Web", id = UrlParameter.Optional },
        new[] { "Nop.Web.Controllers" }
    ).DataTokens["UseNamespaceFallback"] = false;
    

    Same way

    context.MapRoute(
        "Admin_default",
        "Admin/{controller}/{action}/{id}",
        new { controller = "Home", action = "Index", area = "Admin", id = "" },
        new[] { "Nop.Admin.Controllers" }
    );
    

提交回复
热议问题