Copied to clipboard

Flag this post as spam?

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


  • Agnieszka 2 posts 72 karma points
    Jun 06, 2022 @ 10:05
    Agnieszka
    0

    @ViewData Umbraco 8, getting name property for image

    Hi everyone,

    I am sorry for the total newbie question. I have a legacy website and 0 experience with Umbraco or C#. The website was created without alt tags and it is causing accessibility issues. I am working with Umbraco 8.6.8.

    I have subpages using a partial view for the header's content and image.

    <img src="@ViewData["image"]" class="example-class"/>
    

    which gives me URL of the image and @ViewData["content"] which provides me with the content of the field used in CMS. I am trying to get the name property of the image to use in the alt tag. I searched google and forum and tried multiple combinations of .Name and .GetPropertyValue with no success so far.

    Can anyone give me some advice on how to do it properly?

    Thank you.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jun 08, 2022 @ 03:33
    Dennis Aaen
    0

    Hi Agnieska

    First of all welcome to Our

    As I remember correct then you have reaced out to Umbraco support about this where we found a solution for you.

    It would be super cool of you could share the solution in here, so others that might have the same question in the future can find how you solved it

    All the best,

    /Dennis

  • Agnieszka 2 posts 72 karma points
    Jun 10, 2022 @ 11:44
    Agnieszka
    0

    Hi there,

    First thank you so much Dennis for helping me out with this.

    In regards to answer, for people who will look for this in the future: In the Templates in Settings we can create a Model and reference variables.

    var image = item.Value<IPublishedContent>("image"); @Html.Partial("~/Views/Partials/Sections/nameofpage.cshtml", new ViewDataDictionary{ { "image", @image.Url}, { "content", @item.Value("content")}, { "altText", @image.Name}, })

    and then we can access it in via @ViewData in partial views.

Please Sign in or register to post replies

Write your reply to:

Draft