MVC 4 Area Routing is not working

后端 未结 6 989
误落风尘
误落风尘 2021-02-14 07:39

I created an empty MVC4 Application, all things are working fine, after that I add an Area to my Project Named \"Moderator\". My area routing code is like this:



        
6条回答
  •  渐次进展
    2021-02-14 08:13

    I had the same problem. You look to App_Start/RouteConfig.cs and add top this code AreaRegistration.RegisterAllAreas();

    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            AreaRegistration.RegisterAllAreas();
    
            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
    }
    

    Create create Areas/Moderator/Controllers/DashboardController.cs

    public class DashboardController : Controller
    {
        //
        // GET: /Moderator/Dashboard/
    
        public ActionResult Index()
        {
            return View();
        }
    }
    

    and create

    Areas/Moderator/Views/Dashboard/Index.cshtml

    You also need to have Web.config in Areas/Moderator/Views/Web.config ...

提交回复
热议问题