MVC 4 Area Routing is not working

后端 未结 6 1007
误落风尘
误落风尘 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:26

    Just add the "namespace:" named parameter in RegisterRoutes() method of RouteConfig.cs in App_Start folder. And specify the value of "namespace" to the namespace of your controller, within which you want to call action method. In following example i want to call Index() method in Village Controller from root of project.

    public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Village", action = "Index", id = UrlParameter.Optional },
                namespaces: new string[] { "MvcApplication1.Controllers" }
            );
        }
    

提交回复
热议问题