Copied to clipboard

Flag this post as spam?

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


  • J 445 posts 862 karma points
    Aug 04, 2022 @ 11:40
    J
    0

    Correct way to redirect to another page with id?

    I have a TestFormController inheriting from SurfaceController.

    I render the form in a template (which has a doc type too) as

    Html.RenderAction("RenderForm", "TestFormSurface"); 
    

    This returns a partial View and the form is displayed.

    The current view can be considered as a List of products. Therefore i am looping through the products in the HTML of this partial.

    Part of this HTML i would like this to click the product to take it to its own page.

    I am about to create a new template (maybe doc type) for a single product so when the user clicks this product in the list it redirects to a new page along with the ID so i can look up the product from my database.

    I thought about using @Html.ActionLink but the URL isnt matching.

    I then became a little confused when reading about Route Hijacking and wondering if i need to do this in another simpler way?

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Aug 14, 2022 @ 14:47
    Marc Goodson
    100

    Hi J

    In your Foreach loop of Products, then each 'product' will represent the content item in Umbraco (eg IPublishedContent) and therefore you can use the .Url() method to get the Url for the user to navigate to the individual product page eg

    @{
    // not sure how you get your products but if this view is the page above where the ProductPage DocTypes are created then something like this would find them:
    var allMyProducts = Model.Children().OfType<ProductPage>();
    }
    <ul>
    @foreach (var product in allMyProducts){
    
    <li><a href="@product.Url()">@product.Name</a></li>
    }
    </ul>
    

    regards

    marc

Please Sign in or register to post replies

Write your reply to:

Draft