I have created an custom controller to display products from the databae, the custom controller is called CatalogueController. All the code to extract data from database is in controller's Index action. This action is working fine. But the problem arises when I try to call controllers other method to display product types. The action getAllTypes return partial view of product types.
But when I call action from the view :
@Html.Action("getAllTypes ", "Catalogue")
I get error :
System.InvalidOperationException: No route in the route table matches the supplied values.
Hi. Normally you don't call RenderMvcController's directly, they are instantiated via the Umbraco pipepline and then returned to a view that inherits from a custom render model.
So you'd create a model that inherits from RenderModel - say MyModel. Now say MyModel has an IEnumerable<string> property called ItemsList.
In your RenderMvcController you'd populate MyModel.ItemsList from wherever (your custom DB, perhaps).
Then in your template you'd inherit from
@inherits UmbracoViewPage<MyModel>
Then in your view you can just access the items in your model simply by
@foreach (var item in Model.ItemsList)
{
<p>@item</p>
}
Rendering Partial View
Hi,
I have created an custom controller to display products from the databae, the custom controller is called CatalogueController. All the code to extract data from database is in controller's Index action. This action is working fine. But the problem arises when I try to call controllers other method to display product types. The action getAllTypes return partial view of product types. But when I call action from the view :
I get error :
Any idea?
Thanks
Is this a standard MVC controller, rather than a surface controller? Sounds like you need to register the route:
https://our.umbraco.org/documentation/Reference/Routing/custom-routes
Hi Dan, Controller is inherited from Umbraco.Web.Mvc.RenderMvcController. Do I still have to register the route.
Thanks
Hi. Normally you don't call RenderMvcController's directly, they are instantiated via the Umbraco pipepline and then returned to a view that inherits from a custom render model.
So you'd create a model that inherits from RenderModel - say
MyModel
. Now sayMyModel
has anIEnumerable<string>
property calledItemsList
.In your RenderMvcController you'd populate
MyModel.ItemsList
from wherever (your custom DB, perhaps).Then in your template you'd inherit from
Then in your view you can just access the items in your model simply by
See
https://our.umbraco.org/Documentation/Reference/Routing/custom-controllers
is working on a reply...