Copied to clipboard

Flag this post as spam?

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


  • Saltuk 8 posts 98 karma points
    Sep 06, 2020 @ 19:29
    Saltuk
    0

    cant get image from a class

    @using CleanBlog.Core.Helpers

    @inherits UmbracoViewPage

    @{ var articleList = Model.Root().Descendants

    ().Where(x => x.IsVisible()).OrderByDescending(y => y.ArticleDate);

    var isArticleListPage = articleList.Id == Model.Id;
    var fallbackPageSize = isArticleListPage ? 10 : 3;
    
    var pageNumber = QueryStringHelper.GetIntFromQueryString(Request, "page", 1);
    var pageSize = QueryStringHelper.GetIntFromQueryString(Request, "size", fallbackPageSize);
    
    var pageOfArticles = articles.Skip((pageNumber - 1) * pageSize).Take(pageSize);
    var totalItemCount = articles.Count();
    var pageCount = totalItemCount > 0 ? Math.Ceiling((double)totalItemCount / pageSize) : 1; }
    

    @if (articles != null && articles.Any()) {

            @foreach (var article in pageOfArticles)
            {<img class="img-fluid"src="@(article.ArticleImage).Url" alt="sa" />
    

    }

    i can reach other props like article.DateTime or article.AuthorName but src looks like this src="Umbraco.Web.PublishedModels.Image().Url"

  • Marc Goodson 2138 posts 14321 karma points MVP 8x c-trib
    Sep 07, 2020 @ 07:41
    Marc Goodson
    100

    Hi Slatuk

    Try

      @foreach (var article in pageOfArticles)
            {<img class="img-fluid"src="@(article.ArticleImage.Url)" alt="sa" />
    

    instead!

    Everything inside the @() brackets is written out to the template, so you were seeing the Media Object Class name written out, but you want the .Url property of that object to be written out, and so the .Url bit needs to be inside the @() brackets

    regards

    Marc

  • Saltuk 8 posts 98 karma points
    Sep 14, 2020 @ 06:55
    Saltuk
    0

    thank you sir

Please Sign in or register to post replies

Write your reply to:

Draft