MVC 4 Area Routing is not working

后端 未结 6 1581
伪装坚强ぢ
伪装坚强ぢ 2021-02-14 08:09

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:34

    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 ...

提交回复
热议问题