Reputation: 903
I'm trying to use Html.RenderAction in ASP.NET MVC 2 RC2 in this way:
In Menu Controler:
[ChildActionOnly]
public ActionResult ContentPageMenus()
{
var menus = _contentPageMenuRepository.GetAll().WithCulture(CurrentCulture);
return PartialView(menus);
}
And in my Index view (for Index action of Home controller):
<% Html.RenderAction("ContentPageMenus", "ContentPageMenu");%>
But I always get this error message: No route in the route table matches the supplied values.
Upvotes: 17
Views: 12334
Reputation: 2135
I have had this issue before, it was where the route didn't include the controller.
context.MapRoute(
"Route_default",
"Stuff/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
I still wanted to be able to call an action straight after the Area so i added the following route like so.
context.MapRoute(
"Route_default",
"Search/{action}/{id}",
new { controller = "Search", action = "Index", id = UrlParameter.Optional }
);
context.MapRoute(
"Route_Controller",
"Stuff/{controller}/{action}/{id}",
new { controller = "Something", action = "Index", id = UrlParameter.Optional }
);
Upvotes: 0
Reputation: 4608
Adding a third parameter like this was the solution for me (in razor):
@{Html.RenderAction("ActionName", "ControllerName", new { area = string.Empty });}
Upvotes: 14
Reputation: 765
I had the same error. It was caused by altering the default route; apparently it explicitly searches for a route name "Default".
Upvotes: 6
Reputation: 131192
MVC Futures used to allow rendering of actions that had no routes. This has changed in ASP.NET MVC2.
If you want RenderAction to work and would like to hide your route so its not publicly accessible.
globals.asax.cs
.[ChildActionOnly]
attribute.Upvotes: 11
Reputation: 6059
Why don't you try using the strong typed method?
Try this:
<% Html.RenderAction<ContentPageMenusController>(x => x.ContentPageMenus()); %>
You have to fill the exactly name of the class.
Upvotes: 0
Reputation: 4886
What is your controller's name? By default the following is what happens with your routes.
The Controller name specified in your RenderAction method is searched for with "Controller" appended to that name.
The Action method in that Controller gets called and a View returned.
So, by looking at your code, the following will happen
This is assuming that you haven't changed the defaulting routing and haven't added new ones that will affect your routing
Upvotes: 6