Copied to clipboard

Flag this post as spam?

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


  • lasse madsen 5 posts 95 karma points
    Sep 03, 2018 @ 18:34
    lasse madsen
    0

    Outputting value from Partial View

    Hi guys,

    I'm trying to output my partial view on my front page. However, it won't allow me to output some of my values (data type values). At the moment i try to list out the datatype i made for a blog post (a title in a h2). It will not be shown. I think it has something to do with me not allowing content from other datatypes to appear on some sites. But im not sure.

    Heres my partial view. At the very top is the following code:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

    @{
    var selection = Model.Content.Site().FirstChild("portfolio").Children()
                        .Where(x => x.IsVisible())
                        .OrderBy("CreateDate desc");
    

    }

    @foreach(var item in selection){
            <div class="flex-wrapper">
                <div class="flex-item">
                    @{
                        var postImage = item.GetPropertyValue<IPublishedContent>("specificProjectMainImage");
                        if (postImage != null)
                        {
                            <img src="@postImage.Url" style="width: 100%;" alt="@postImage.GetPropertyValue("alt")" />
                        }
                    }   
    
                </div>
                <div class="flex-item blogItemText">
                    <h2>@Umbraco.Field("kontaktHeader")</h2>
                    <p>@Umbraco.Field("specificProjectTeaser")</p>
                </div>
            </div>
    }
    

    So what i basicly want to do is: – Output data from one document type in another document type via partial view.

    Really hope that someone can help me with this. :-)

    If my question is not clear, please let me know and ill try to specify.

    Best regards Lasse

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Sep 03, 2018 @ 22:49
    Marc Goodson
    100

    Hi Lasse

    I think this is because Umbraco.Field will always try to write out a property from the Current Page you are on...

    ... whereas in your for each loop you want to write out the property value from your 'item' in the selection.

    So you should be able to write the header as:

      <div class="flex-item blogItemText">
                    <h2>@item.GetPropertyValue<string>("kontaktHeader")</h2>
                    <p>@item.GetPropertyValue<string>("specificProjectTeaser")</p>
                </div>
    

    to output the values from each 'item'

    If that helps?

    regards

    marc

  • lasse madsen 5 posts 95 karma points
    Sep 04, 2018 @ 08:55
    lasse madsen
    0

    You must be some kind of a sorcerer – it worked like a dream! Thank you so much, Mark!

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Sep 04, 2018 @ 15:11
    Marc Goodson
    1

    Cool!

    Glad it's working for you!, there are possibly 5 different ways to write out the value of an Umbraco property - because of the evolution of Umbraco templating over the years, along with the desire to keep backwards compatibility... so it can get a little confusing!

Please Sign in or register to post replies

Write your reply to:

Draft