Copied to clipboard

Flag this post as spam?

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


  • Dee 24 posts 94 karma points
    Oct 11, 2019 @ 19:47
    Dee
    0

    ImageCropperValue.GetCropUrl not providing the correct url

    hey guys,

    following scenario:

    • defined an Umbraco.ImageCropper data field.
    • defined a crop with the alias "hero", 1600 x 620
    • uploaded an image, using the crop "hero"

    within my home view I'm trying to pass the crop url to the partial view:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<Home>
    @using ProFinder.Core.ViewModels
    
    @{
        Layout = "master.cshtml";
    }
    
    @Html.Partial("~/Views/Partials/header.cshtml", new HeaderViewModel(Model.Name, Model.Title, Model.Subtitle, Model.MainImage.GetCropUrl("hero")))
    

    Model.MainImage is an "ImageCropperValue" within the namespace Umbraco.Core.PropertyEditors.ValueConverters

    My ViewModell:

    public class HeaderViewModel
    {
        public string Name { get; set; }
        public string Title { get; set; }
        public string Subtitle { get; set; }
        public bool HasSubtitle => !string.IsNullOrWhiteSpace(Subtitle);        
        public string BackgroundImageUrl { get; set; }
        public bool HasBackgroundImage => string.IsNullOrEmpty(BackgroundImageUrl);
        public string AuthorName { get; set; }
        public bool HasAuthor => !string.IsNullOrWhiteSpace(AuthorName);
        public DateTime? ArticleDate { get; set; }
        public bool IsArticle => ArticleDate.HasValue;
        public HeaderViewModel(string name, string title,
            string subtitle, string backgroundImageUrl,
            string authorName = null, DateTime? articleDate = null)
        {
            Name = name;
            Title = title;
            Subtitle = subtitle;
            BackgroundImageUrl = backgroundImageUrl;
            AuthorName = authorName;
            ArticleDate = articleDate;
        }
    }
    

    My PartialView:

    @inherits UmbracoViewPage<ProFinder.Core.ViewModels.HeaderViewModel>
    
    @{
        string mainImageUrl = Model.HasBackgroundImage ? Model.BackgroundImageUrl : "img/home_section_1.jpg";
    }
    ...
    <section class="hero_single version_1" style="background-image: url('@mainImageUrl')">
    

    Returned Url in response:

    <section class="hero_single version_1" style="background-image: url('?center=0.41466666666666668,0.11833333333333333&amp;mode=crop&amp;width=1600&amp;height=620')">
    

    Which is not showing up the image.

    Any ideas?

    Thanks

    Dee

  • Dee 24 posts 94 karma points
    Oct 11, 2019 @ 20:04
    Dee
    0

    the solution:

    @Html.Partial("~/Views/Partials/header.cshtml", new HeaderViewModel(Model.Name, Model.Title, Model.Subtitle, Model.MainImage.Src + Model.MainImage.GetCropUrl("hero")))
    
Please Sign in or register to post replies

Write your reply to:

Draft