Copied to clipboard

Flag this post as spam?

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


  • Dean 13 posts 123 karma points
    Apr 04, 2023 @ 12:54
    Dean
    0

    Inherited document type issue

    Hi guys

    Going through a couple of tutorials. I create a document type. Once created I right click this document type and create a child document type.

    I see all the parent fields appear in the child document type. I add a new field on the child only.

    In my view page I write the below code

    var newField = Model.Value("new field");
    

    Even though I have filled this in on my page the value does not come through. I did the same code on the parent field and that seems fine.

    What's wrong here?

    Dean

  • Huw Reddick 1929 posts 6717 karma points MVP 2x c-trib
    Apr 04, 2023 @ 12:56
    Huw Reddick
    0

    try Model.Value("newfield"); (no spaces in alias names)

  • Dean 13 posts 123 karma points
    Apr 04, 2023 @ 13:00
    Dean
    0

    Sorry that was a typo at my end. New field does not contain any spaces.

    Thank you

  • Huw Reddick 1929 posts 6717 karma points MVP 2x c-trib
    Apr 04, 2023 @ 13:03
    Huw Reddick
    0

    Will need some more info then. What does the config of your child document type look like? What does your View page look like?

  • Dean 13 posts 123 karma points
    Apr 04, 2023 @ 13:11
    Dean
    0

    I'll post some code shortly but it's the normal default view page code nothing special so far.

    @{
    var newField = Model.Value("newField");
    }
    

    Then I debug the code to see the value but it's empty. What I did notice in debug mode is if I expanded the Children entry when I hover over Model then I can see the child page.

    Not sure if that narrows it down? I think I need the code which drills into the children?

  • Huw Reddick 1929 posts 6717 karma points MVP 2x c-trib
    Apr 04, 2023 @ 14:29
    Huw Reddick
    0

    Without seeing your setup it is dificult to say exactly what you need to do, but it sounds like your view is displaying the parent not the child page

  • Dean 13 posts 123 karma points
    Apr 04, 2023 @ 15:51
    Dean
    0

    Parent DocumentType called Customers (fields called Name and Surname - to make this simple) I right click and create a new DocumentType called Customer (no S on the end).

    Customer has Name and Surname from Customers and i now add Age to Customer (child documenttype).

    Under content i create a Customers page and under that i create a Customer page.

    My View is simple at present

    @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage
    
    @{
    var newField = Model.Value("name");
    }
    

    I place a breakpoint on the end and i can see the name i passed in from Umbraco Customers page.

    In the Customer page i add the exact same code but for Age

    @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage
    
    @{
    var ageField = Model.Value("age");
    }
    

    But this time I add an age in an Umbraco (Customer) Page but when that page runs age in the above code is always empty.

    So now i go back in debug mode and hover over Model in Visual Studio - when i hover over it i can see a Childrens property and drilling into it through Visual Studio eventually leads me to seeing the value but i dont know how to get to it?

  • Huw Reddick 1929 posts 6717 karma points MVP 2x c-trib
    Apr 04, 2023 @ 17:31
    Huw Reddick
    0

    In the back office is your Customer set to use the correct View, it sounds to me like it is using the Customers View so the model getting passed in is not correct.

    I think you have something set up incorrectly, could you show a screen shot of your content nodes.

Please Sign in or register to post replies

Write your reply to:

Draft