Copied to clipboard

Flag this post as spam?

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


  • Mark Watson 118 posts 384 karma points
    Mar 13, 2019 @ 03:06
    Mark Watson
    0

    Easier way to display page .HasValue

    Is there any easier way to do this, can someone point me in the right direction.

    I have a number of case histories items that have a value (eg "Car Park") via a drop down menu "Catagory". I display all the items on a page (Case Histories) but also have a page for each item (ie Car Park) and wish to display just the items that relate to that page.

    I can do this by creating a document type for each page ie "Case History Car Park" and adding the razor.

        var casesort = Model.Content.Site().FirstChild("caseHistoryPage").Children()
                        .Where(x => x.HasValue("Catagory") && x.GetPropertyValue<string>("Catagory").Equals("Car Park"));
    

    Is there a way that I can use the Document type "Case history" for all pages or do I have to create a Document type for each (Car Park, Maintenance, Painting etc)

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Mar 13, 2019 @ 03:33
    Søren Gregersen
    0

    First of all Model.Content has been changed to "just" Model in v8

    I don't think I understand your question right, but would't you just want to add the "Car park" as a value from the page you are on?

    something like:

    var casesort = Model.Site().FirstChild("caseHistoryPage").Children()
                    .Where(x => x.HasValue("Catagory") && x.GetPropertyValue<string>("Catagory").Equals(Model.Catagory));
    
  • Mark Watson 118 posts 384 karma points
    Mar 13, 2019 @ 04:04
    Mark Watson
    0

    Thanks Soren. Let me try an explain further.

    I have a number of case histories

    enter image description here

    When the client adds a new case history they have a drop down menu to choose the catagory of the Case history.

    enter image description here

    All the Case histories are displayed on the Case History page but I also wish to display just the case histories that relate to the page under services. ie the page /Services/Car Park Upgrades to display the items that just have the catagory "Car Park". The page /Services/Painting to display the items that just have the catagory "painting".

    Does that help?

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Mar 13, 2019 @ 05:39
    Søren Gregersen
    1

    Again, you just needs use a property from the page you are on, to filter the list of related page, like in the code i posted

  • Mark Watson 118 posts 384 karma points
    Mar 13, 2019 @ 05:58
    Mark Watson
    0

    Thanks Soren

    I am new to Umbraco so please bear with me. I tried your code and it returned

    CS1929: 'RenderModel

Please Sign in or register to post replies

Write your reply to:

Draft