MVC 3 - New Area - 404 error - Resource not found - have tried route debugger

后端 未结 3 1843
旧巷少年郎
旧巷少年郎 2021-02-20 10:09

I have a small MVC 3 app - bit of a demo ground. I have one area and thats been working fine.

I have just added another area expecting to just spin up the app and it wor

相关标签:
3条回答
  • 2021-02-20 10:40

    Try to add a class PostCardAreaRegistration under PostCard Area

    using System.Web.Mvc;
    
    namespace Areas.PostCard
    {
        public class PostCardAreaRegistration: AreaRegistration 
        {
            public override string AreaName 
            {
                get 
                {
                    return "PostCard";
                }
            }
    
            public override void RegisterArea(AreaRegistrationContext context) 
            {
                context.MapRoute(
                    "PostCard_default",
                    "PostCard/{controller}/{action}/{id}",
                    new { action = "Index", id = UrlParameter.Optional }
                );
            }
        }
    }
    
    0 讨论(0)
  • 2021-02-20 10:57

    I ran into this when I moved a controller into an Area but forgot to update the namespace. The controller name is scoped to the Area's namespace. So "Some" in "Area" will map to App.Areas.Area.Controllers.SomeController, which didn't exist.

    0 讨论(0)
  • 2021-02-20 11:02

    You were missing the controller part in your maproute

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