@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.
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?
@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.
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.
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
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.
is working on a reply...