Search code examples
c#dotnetnuke2sxc

How can I build a link to navigate to the parent page inside of a 2sxc app using c# razor templates?


I'm building an app that lists out careers in a listing and also has a details template.

The pages in DNN are structured like this: Students (parent) > Organize (child)

I want to make a simple link in the details template (c# razor) to point back to the parent of this child page. So when I'm on Organize, make the link point back to "Students"

Looking through the 2sxc template editor, I see that I can get the parent page's ID using: @Dnn.Tab.ParentId but I'm not sure how to construct a link using that ID.

But how can I make a link to the parent page?


Solution

  • One simple thing you can always do is just href="/tabid/nnn" - so

    <a href="/tabid/@Dnn.Tab.ParentId">Up</a>
    

    Based on your description, I am not sure that covers you 100% of the time, but seemed worth pointing out. :)

    If you prefer a more "code" approach, use 2sxc's Link.To()...

    <a href="@Link.To(pageId: Dnn.Tab.ParentId, parameters: "this=403&category=all")">Up</a>
    

    Reference