I have started using asp .net mvc and I am getting some trouble with the routing. I want to have a partial view in the layout file. I also have areas. My routing is as follows:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { area = "Home", controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
null
).DataTokens.Add("area", "Home");
// home and error page
routes.MapRoute("", "error", new { area = "", controller = "Home", action = "Error" });
routes.MapRoute("home_default", "", new { area = "Home", controller = "Home", action = "Index" });
I am trying to use
@{ Html.RenderAction("Index", "_Menu"); }
in the layout file. I have define a _Menu
controller in the controllers folder outside the areas. I am actually getting
The controller for path '/project/' was not found or does not implement IController.
Is there a way to do that?
Calling:
Html.RenderAction("Index", "_Menu");
Is exactly the same as calling this RenderAction :
Html.RenderAction("Index", "_Menu", new { area = "<currentArea>" });
So if you want to make sure a call is to the non-area controller you need to:
Html.RenderAction("Index", "_Menu", new { area = ""});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.