Copied to clipboard

Flag this post as spam?

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


  • Lasse Offt 8 posts 98 karma points
    Nov 16, 2021 @ 09:55
    Lasse Offt
    0

    Umbraco 9, link from one template\view to another, how?

    I've become a bit confused on how to actually do this.

    I have a link on my footer, which is rendered from master with a partial view. I have a CookieDeclaration.cshtml in root of my Views folder and i want to link to this from my footer.

    How is the approach? I've been playing around with RenderController, but i'm unable to get it to hit my controller with:

    HomeController

    public class HomeController : RenderController
    {
            public IActionResult CookieDeclaration()
            {
                var vm = new CookieDeclarationViewModel(CurrentPage);
                return View("/Views/CookieDeclaration.cshtml", vm);
            }
    

    Views\Partials\footer.cshtml

    @Html.ActionLink("CookieDeclaration", "CookieDeclaration", "Home", new { }, null)
    

    Or

    CookieDeclarationController

    public class CookieDeclarationController : SurfaceController
    {
            public IActionResult Index()
            {
                var vm = new CookieDeclarationViewModel(CurrentPage);
                return View("/Views/CookieDeclaration.cshtml", vm);
            }
    

    Views\Partials\footer.cshtml

    @Html.ActionLink("CookieDeclaration", "Index", "CookieDeclaration", new { }, null)
    

    What am i doing wrong? Should i use a ViewComponenent instead, haven't tried using them before yet, though.

    Can i simply link to CookieDeclaration.cshtml without a controller?

  • Lasse Offt 8 posts 98 karma points
    Nov 21, 2021 @ 16:30
    Lasse Offt
    0

    Are no one able to help me here?

  • Paul Seal 524 posts 2889 karma points MVP 6x c-trib
    Nov 22, 2021 @ 15:52
    Paul Seal
    100

    Hi You shouldn't need a controller to link to a page if the page exists in umbraco as a page.

    You should be able to link directly to it using the url. /cookie-declaration/

    You could have a property on your home page called Footer Links and you could use a Multi Url Picker data type.

    Then in the content editor you can choose the links for the footer, this would include your cookie declaration page.

    Next you could update your Footer.cshtml to read the Footer Links property from your home page and loop through them to render them in the footer.

    That's how I would do it.

    I hope this helps.

    Paul

  • Lasse Offt 8 posts 98 karma points
    Nov 22, 2021 @ 16:26
    Lasse Offt
    0

    That was actually a pretty simple solution, didn't think of that...

    Of cause, it's obvious now.

    Thanks a ton.

Please Sign in or register to post replies

Write your reply to:

Draft