Copied to clipboard

Flag this post as spam?

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


  • iNETZO 93 posts 412 karma points
    Nov 05, 2019 @ 14:09
    iNETZO
    0

    Routing via template not working in Umbraco 8

    Hi,

    In Umbraco 7 i used template routing to do a custom action to create another overview.

    In Umbraco 8 i can't get this to work. I followed the instructions in https://our.umbraco.com/Documentation/Reference/Routing/custom-controllers#routing-via-template. But instead of hitting the contoller action, a 404 page is displayed. I tried it with a the Umbraco 8 Staterkit and used the folllow class:

    public class BlogController : Umbraco.Web.Mvc.RenderMvcController
    {
        public ActionResult Index(ContentModel model)
        {
    
            return base.Index("defaultview", model);
        }
    
        public ActionResult Test(ContentModel model)
        {
    
            return base.Index("customview", model);
        }
    

    Then i've added a template to the documenttype Blog with the name "Test".

    When i do the same with Umbraco 7.15.3, the test-action is hit when i use https://localhost:xxxxx/blog/test

    Has this been changed to Umbraco 8 or is this a bug?

    Best regards,

    iNETZO

  • Steve Megson 150 posts 942 karma points MVP c-trib
    Nov 05, 2019 @ 14:44
    Steve Megson
    101

    By default in Umbraco 8, selecting a different template by adding a template alias to the end of the URL isn't enabled. You can enable it as described here. Without that change, when you request https://localhost:xxxxx/blog/test it's just looking for a page with that URL and can't find one, so you get a 404.

    The routing by template for custom controllers is talking about routing based on the template assigned to the page, rather than changing the template based on the URL. If you change the template of the Blog page to Test, you should find that https://localhost:xxxxx/blog/ will use your Test action.

  • iNETZO 93 posts 412 karma points
    Nov 05, 2019 @ 19:45
    iNETZO
    0

    Hi Steve,

    Thanks for your reply, it helped me fixing the problem! After adding the contentfinder "ContentFinderByUrlAndTemplate" to my composer the template routing worked like as in Umbraco 7.

    Best regards,

    iNETZO

Please Sign in or register to post replies

Write your reply to:

Draft