Copied to clipboard

Flag this post as spam?

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


  • Andy Felton 185 posts 484 karma points c-trib
    Nov 29, 2018 @ 22:29
    Andy Felton
    0

    Controllers and views

    Hi,

    I have a Document Type (Course) and Content Items (e.g. item) within the Umbraco back office, this is normally displayed using the URL like https://mysite.com/myparent/item. I use a controller CourseController through route hijacking and view Course.chtml to render this. What I'd like, is to have an alternative view TakeCourse.chtml that uses the same controller with a different action (TakeCourse) and is accessed by the URL https://mysite.com/myparent/item/takecourse.

    I've spent a while looking for how to set this up but am not finding much at the moment.

    Any help/advice/links anybody can be provide will be appreciated.

    Thanks Andy

  • Marc Goodson 2155 posts 14406 karma points MVP 9x c-trib
    Nov 30, 2018 @ 16:44
    Marc Goodson
    100

    Hi Andy

    It should be enough to have an Action in your controller with a name matching the name of your alternative template.

    https://our.umbraco.com/documentation/reference/routing/custom-controllers#routing-via-template

    You may need to allow your document type to 'use' the alternative template you have created in the backoffice..

    In your alternative action if you return like so:

    return CurrentTemplate(yourmodel);

    then the CurrentTemplate helper is clever enough to know you requested the page via the url that would trigger the altTemplate, and returns your alternative template view.

    Final thing to check if it's not working, is in config/umbracosettingsconfig in the routing element to make sure altTemplates aren't turned off!

      <web.routing
        trySkipIisCustomErrors="true"
        internalRedirectPreservesTemplate="false" disableAlternativeTemplates="false" disableFindContentByIdPath="false"
        umbracoApplicationUrl="">
      </web.routing>
    

    regards

    Marc

  • Andy Felton 185 posts 484 karma points c-trib
    Dec 01, 2018 @ 17:49
    Andy Felton
    0

    Thanks Marc,

    That sorted it was simply a matter that I hadn't added the alternative template to the document type in the backoffice - did that and it worked straight away!

    Thanks Andy

Please Sign in or register to post replies

Write your reply to:

Draft