Html.Block(item) - No route in the route table matches the supplied values

Hi, we are moving all our views into “Areas” and using that MVC logic to have different views based on domain but keeping the same Controllers.

But now the Html.Block(item) function can’t find the controllers? The right controller and action are set on the block field type, same as before, but we get this error: No route in the route table matches the supplied values.

Can we get some information on how the Html.Block(item) functions works behind the scene? Does it call the action with the Area prefix? If so, We could maby add controllers routs for all the areas?

In the inner part of all chains of methods the htmlHelper.RenderAction is executed as below

htmlHelper.RenderAction(templateControllerAction.Action, templateControllerAction.Controller, routeValues: routeValueDictionary);

You can try to call it like Html.Block(item, new { area: "MyArea" }) but I’m not sure if that will work.

Update: Regarding to https://stackoverflow.com/questions/14106096/html-renderaction-from-different-directory it should work to add the area in the routeValues object.

1 Like

This saved the day!

@Html.Block(item, new { area = “” })

Thanks!