Html.RenderAction causes "No route in the route table matches the supplied values"

Viewed 12068

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.

7 Answers

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

  1. You should have a Controller called "ContentPageMenuController"
  2. You should have an Action called "ContentPageMenus" which you have
  3. You should have a view called ContentPageMenus()

This is assuming that you haven't changed the defaulting routing and haven't added new ones that will affect your routing

Have you registered any additional routes for you application?

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.

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 }
        );
Related