Copied to clipboard

Flag this post as spam?

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


  • Hugo Migneron 32 posts 105 karma points
    Oct 14, 2013 @ 07:13
    Hugo Migneron
    0

    Links with parameters inside Razor View

    Hi,

    Inside my umbraco website, I want a section in which the content is pulled from a regular database (not from the Umbraco CMS). I want to the section to display a list of items. When I click on an item, I can edit it in a form and save it.

    I followed the docs to highjack the routes here : http://our.umbraco.org/documentation/reference/Templating/Mvc/custom-controllers and it works (as in I can highjack the route, display the list of items, and on the details page, the post with the SurfaceController also works). I created 2 DocTypes and 2 templates. One for the index page and one for the details page. My arborescence looks like : 

    • Homepage
      • Index
        • Details

    My problem is that I don't know how to link the Index and Details page together. In my "Index" view where I list the items, how do I create a link to the "Details" view?

    In my Index view, I have : 

    @{
        var detailsNode = Model.Content.Children.Where(c => c.DocumentTypeAlias == "ItemDetails").FirstOrDefault();
    }
    @foreach (var item in Model.Items)
    {
    <a href="@detailsNode.Url()">@item.Title</a> }

    This sort of works, but I don't get the ID of the item I want. How do I pass it? Url() doesn't take a parameter. I know I could add a query string manually but it feels to hackish to be the way to go.

    What is the correct way of doing what I am trying to do? Is the 2 content pages approach right (creating a link based only on the fact that it is the children feels wrong)? If so, how do I pass the item from the Index page to the Details page, and how do I fetch it back once I am on the Details page? I understand that @Html.ActionLink doesn't work because of Umbraco's routing engine but how do I get the equivalent?

    Sorry for the long post, I am new to Umbraco and unsure of what details are relevant to this problem. If I am being unclear, please let me know.

    Thank you for your help!

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Oct 14, 2013 @ 22:45
    Jeavon Leopold
    100

    Hi Hugo,

    Welcome to Our! I think you are after a Custom Route, there is a great post by Shannon about how to do this here

    Jeavon

  • Hugo Migneron 32 posts 105 karma points
    Oct 15, 2013 @ 19:07
    Hugo Migneron
    0

    Thank you Jeavon. Sorry it took a while for me to get back to you, it also took a while for me to fully understand that post!

    Custom routes were what I was after. Didn't find them initially in the docs so thanks for the link, helped me tons!

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Oct 15, 2013 @ 19:25
    Jeavon Leopold
    0

    Hi Hugo,

    Great news! There is one page of documentation about custom routes but it mainly leads you to that same post by Shannon.

    http://our.umbraco.org/documentation/Reference/Templating/Mvc/custom-routes

    Jeavon

Please Sign in or register to post replies

Write your reply to:

Draft