Copied to clipboard

Flag this post as spam?

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


  • demo 12 posts 133 karma points
    Feb 20, 2018 @ 14:39
    demo
    0

    Child pages image not display terrible !

    i have 2 doctype articles main and articles item

    and i have one partial view listarticlesinhomepage

    now foreach loop work good but only display item url and name

    when i write item.articlePhotos get errors

    please help me :((

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    

    @foreach (var child in Model.Content.AncestorOrSelf().Children.Where(c => c.DocumentTypeAlias.Equals("articlesMain"))) {

                            <div class="container marketing">
    
                            @if(child.Children.Any(x => x.DocumentTypeAlias.Equals("articlesItem")))
                            {
    
                                <div class="row">
                                    @foreach(var page in child.Children.Where(p => p.DocumentTypeAlias.Equals("articlesItem")))
                                    { 
    
    
    
    
                                        <div class="col-lg-4">
    
    
                                           <img src="@item.articlePhotos" /> <!--this line get error please help-->
                                            <h2>@page.Name</h2>
                                            <p><a class="btn btn-secondary" href="@page.Url" role="button">View details &raquo;</a></p>
    
                                        </div>
                                    }
                                    </div>
    
                            }
                            </div>
    
                    }   
    
  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Feb 22, 2018 @ 07:44
    Alex Skrypnyk
    100

    Hi Demo

    Try this code:

    @foreach (var page in child.Children.Where(p => p.DocumentTypeAlias.Equals("articlesItem")))
                    {
                        var mediaItem = item.GetPropertyValue<IPublishedContent>("articlePhotos");
                        <div class="col-lg-4">
    
                            @if (mediaItem != null)
                            {
                                <img src="@mediaItem.Url" />
                            }<!--this line get error please help-->
                            <h2>@page.Name</h2>
                            <p><a class="btn btn-secondary" href="@page.Url" role="button">View details &raquo;</a></p>
    
                        </div>
                    }
    

    Alex

  • demo 12 posts 133 karma points
    Feb 23, 2018 @ 13:02
    demo
    0

    Thanks Alex. ! Working now...

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Feb 23, 2018 @ 13:26
    Alex Skrypnyk
    0

    I'm glad to help, have a nice weekend

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Feb 23, 2018 @ 13:31
    Dan Diplo
    2

    Just a quick note that there's a shorter way of doing this:

    @foreach (var page in child.Children.Where(p => p.DocumentTypeAlias.Equals("articlesItem")))
    

    which is:

    @foreach (var page in child.Children("articlesItem"))
    
  • demo 12 posts 133 karma points
    Feb 27, 2018 @ 10:43
    demo
    0

    thanks

Please Sign in or register to post replies

Write your reply to:

Draft