Rendering action from base controller, getting route not defined error

895 views Asked by At

I have a base controller all my other controllers inherit from, inside the base controller are 2ActionResult that is common to every page on my site. When I try to use Html.RenderAction to call either of these actions from a View I get the error

No route in the route table matches the supplied values.

I have checked and the Action is set to public and the names are spelled right. What am I doing wrong?

The call: @{ Html.RenderAction("SectionNavigation"); }

The Action:

[Route("SectionNavigation")] public ActionResult SectionNavigation()

As you can see I am also using Attribute Routing as well. I also tried updated the call to specify Base as the controller but that did not change anything.

1

There are 1 answers

0
haim770 On BEST ANSWER

The first parameter of the RenderAction method is the action name, not the route name.

If you're rendering a View that is being generated using a Controller other than the one that defines the SectionNavigation Action, you'll have to specify the Controller name as well:

@Html.RenderAction("SecondNavigation", "YourControllerName").

If you're using Areas, you'll have to include the Area name as well:

@Html.RenderAction("SecondNavigation", "YourControllerName", new { Area = "MyAreaName" }).

See Documentation