Copied to clipboard

Flag this post as spam?

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


  • kyle 49 posts 240 karma points
    Nov 30, 2021 @ 06:52
    kyle
    0

    Allowing editor to update image

    Hello All, I need some help adding images to my site,

    I have I doctype where the editor can select an image and that doctype has a template with code similar to the code below:

    <img src="@Model.Value("imageAlias").Url()">
    

    this does not work..... I get a compilation error saying there is no method for Url

    But when I use this:

    @{
           var firstBlockImage = Umbraco.Media(Guid.Parse(imageid));
    
    
          var firstBlockImageUrl = firstBlockImage.Url();
    }
    <img src="@ firstBlockImageUrl" />
    

    it obviously works, but this is static and not very efficient,

    I want the editor to select an image they want and it will update accordingly,

    I'm an intern dev in need of help :\

  • Frank Laumann 39 posts 303 karma points
    Nov 30, 2021 @ 06:59
    Frank Laumann
    1

    Hi Kyle

    Try this:

    <img src="@(Model.Value("imageAlias").Url())">
    

    Best regards Frank

  • kyle 49 posts 240 karma points
    Nov 30, 2021 @ 07:09
    kyle
    0

    Hi again Frank! Thanks for you assitance,

    I did what you suggested and got another compilation error..


    *Compilation Error Description:

    An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS1929: 'object' does not contain a definition for 'Url' and the best extension method overload 'PublishedContentExtensions.Url(IPublishedContent, string, UrlMode)' requires a receiver of type 'IPublishedContent'*


    Source Error:

    Line 146:                <div class="partners-item partners-item1">
    Line 147:                    
    Line 148:                    <img src="@(Model.Value("whyDsgFirstCardImage").Url())" alt=""/>
    Line 149:                    <h1>@Model.Value("leftColumnHeader")</h1>
    Line 150:      </div>
    
  • Frank Laumann 39 posts 303 karma points
    Nov 30, 2021 @ 07:31
    Frank Laumann
    100

    Okay, try this:

    <img src="@(Model.Value<IPublishedContent>("imageAlias").Url())">
    
  • kyle 49 posts 240 karma points
    Nov 30, 2021 @ 07:59
    kyle
    0

    You're a lifesaver, Frank! Really appreciate it you have no idea...

    Have a good day!

Please Sign in or register to post replies

Write your reply to:

Draft