Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Fahad Ayub 71 posts 238 karma points
    Mar 06, 2017 @ 13:08
    Fahad Ayub
    0

    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 :

    @Html.Action("getAllTypes ", "Catalogue")
    

    I get error :

    System.InvalidOperationException: No route in the route table matches the supplied values.
    

    Any idea?

    Thanks

  • Dan Diplo 1554 posts 6205 karma points MVP 5x c-trib
    Mar 06, 2017 @ 13:19
    Dan Diplo
    0

    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

  • Fahad Ayub 71 posts 238 karma points
    Mar 06, 2017 @ 13:22
    Fahad Ayub
    0

    Hi Dan, Controller is inherited from Umbraco.Web.Mvc.RenderMvcController. Do I still have to register the route.

    Thanks

  • Dan Diplo 1554 posts 6205 karma points MVP 5x c-trib
    Mar 06, 2017 @ 13:52
    Dan Diplo
    100

    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>
    }
    

    See

    https://our.umbraco.org/Documentation/Reference/Routing/custom-controllers

Please Sign in or register to post replies

Write your reply to:

Draft