MVC4 Default route when using areas

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

    Add the Index action method in your default root home controller. In the Index action method use "return redirecttoaction" statement for the default area redirection

        public ActionResult Index()
        {
            return RedirectToAction("Dashboard", "Home", new {area = "Home"});
        }
    

    Default route should be

     routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new {controller = "Home", 
    action = "Index", id = UrlParameter.Optional}
                    );
    
    0 讨论(0)
  • 2021-02-03 13:26

    default route is by default route in MVC will call at first because in MVC which route is specified very first it will call like that

    0 讨论(0)
提交回复
热议问题