# Accessing custom image properies in Templates via ModelsBuidler

**URL:** <https://forum.umbraco.com/t/accessing-custom-image-properies-in-templates-via-modelsbuidler/8532>\
**Category:** Questions\
**Tags:** v17\
**Created:** [September 11, 2026, 10:17am UTC](https://forum.umbraco.com/t/accessing-custom-image-properies-in-templates-via-modelsbuidler/8532 "2026-09-11T10:17:16Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eaglef90](https://forum.umbraco.com/user_avatar/forum.umbraco.com/eaglef90/32/1014_2.png) [@Eaglef90](https://forum.umbraco.com/u/Eaglef90)\
**Post date:** [September 11, 2026, 10:17am UTC](https://forum.umbraco.com/t/accessing-custom-image-properies-in-templates-via-modelsbuidler/8532/1 "2026-09-11T10:17:16Z")

</div>

I added a custom property “umbracoAltText” to the image media data type as a text string and am now trying to access it in my templates via the Model. I tried `@Model.ImagePropertyName.umbracoAltText` but it is not recognized, in fact none of the “label” properties like width or height are.

I saw the docs page at [Rendering Media | CMS 17.latest (LTS) | Umbraco Documentation](https://docs.umbraco.com/umbraco-cms/17.latest/develop-with-umbraco/templating-and-rendering/design/rendering-media) where they cast the image to an `Umbraco.Media` type but I was hoping there might be some way to access the properties from within the model and not have to cast as will be really annoying to have to cast lots of images on a single page.

---

<div class="post-metadata">

**Author:** ![justin-nevitech](https://forum.umbraco.com/user_avatar/forum.umbraco.com/justin-nevitech/32/6219_2.png) [@justin-nevitech](https://forum.umbraco.com/u/justin-nevitech)\
**Post date:** [September 11, 2026, 10:28am UTC](https://forum.umbraco.com/t/accessing-custom-image-properies-in-templates-via-modelsbuidler/8532/2 "2026-09-11T10:28:58Z")

</div>

Hi @Eaglef90

The media property will be of type `MediaWithCrops`:

> **[Image Cropper | CMS | Umbraco Documentation](https://docs.umbraco.com/umbraco-cms/model-your-content/property-editors/built-in-umbraco-property-editors/image-cropper)**

To get the underlying image, you will need to do something like this:

```auto
var image = Model.MyImageProperty.Content as Image;

if (image != null)
{
    var altText = image.UmbracoAltText;
}

```

You could create an extension method if you want to avoid doing this in multiple places.

Justin

---

<div class="post-metadata">

**Author:** ![justin-nevitech](https://forum.umbraco.com/user_avatar/forum.umbraco.com/justin-nevitech/32/6219_2.png) [@justin-nevitech](https://forum.umbraco.com/u/justin-nevitech)\
**Post date:** [September 11, 2026, 10:44am UTC](https://forum.umbraco.com/t/accessing-custom-image-properies-in-templates-via-modelsbuidler/8532/3 "2026-09-11T10:44:31Z")

</div>

Also, you can directly do this but it would bypass the strongly typed models.

`@Model.MyImageProperty?.Value<string>("umbracoAltText")`

---

<div class="post-metadata">

**Author:** ![Eaglef90](https://forum.umbraco.com/user_avatar/forum.umbraco.com/eaglef90/32/1014_2.png) [@Eaglef90](https://forum.umbraco.com/u/Eaglef90)\
**Post date:** [September 11, 2026, 10:47am UTC](https://forum.umbraco.com/t/accessing-custom-image-properies-in-templates-via-modelsbuidler/8532/4 "2026-09-11T10:47:02Z")

</div>

So I do have to cast each image, very annoying if the page has say 10 images in it then I have to cast every single image. I guess for ease of usage I will have to use the `Value` command. Would I be correct that if an editor forgets to add a value to the property calling it like in your example would simply print out nothing or would it fail and error out?

---

<div class="post-metadata">

**Author:** ![justin-nevitech](https://forum.umbraco.com/user_avatar/forum.umbraco.com/justin-nevitech/32/6219_2.png) [@justin-nevitech](https://forum.umbraco.com/u/justin-nevitech)\
**Post date:** [September 11, 2026, 10:57am UTC](https://forum.umbraco.com/t/accessing-custom-image-properies-in-templates-via-modelsbuidler/8532/5 "2026-09-11T10:57:07Z")

</div>

You can create an extensions method, something like this:

```auto
public static string? AltText(this MediaWithCrops? media)
{
    if (media?.Content is not Image image)
    {
        return null;
    }

    return string.IsNullOrWhiteSpace(image.UmbracoAltText)
        ? image.Name
        : image.UmbracoAltText;
}

```

Then just call:

```auto
@Model.MyImageProperty.AltText()

```

Justin

---

<div class="post-metadata">

**Author:** ![Eaglef90](https://forum.umbraco.com/user_avatar/forum.umbraco.com/eaglef90/32/1014_2.png) [@Eaglef90](https://forum.umbraco.com/u/Eaglef90)\
**Post date:** [September 11, 2026, 11:27am UTC](https://forum.umbraco.com/t/accessing-custom-image-properies-in-templates-via-modelsbuidler/8532/6 "2026-09-11T11:27:00Z")

</div>

Sorry for this stupidity but I have never heard of an “extensions method” doing a bit of digging it seems like this is a c# file I create with your example code and I can get away with just adding an `@using` statement in the `ViewImports.cshtml` file. Is that correct or is there something I need to do to get Umbraco to wire it up?

---

<div class="post-metadata">

**Author:** ![justin-nevitech](https://forum.umbraco.com/user_avatar/forum.umbraco.com/justin-nevitech/32/6219_2.png) [@justin-nevitech](https://forum.umbraco.com/u/justin-nevitech)\
**Post date:** [September 11, 2026, 11:39am UTC](https://forum.umbraco.com/t/accessing-custom-image-properies-in-templates-via-modelsbuidler/8532/7 "2026-09-11T11:39:51Z")

</div>

Hi @Eaglef90

Yes, it’s a C# thing - you add it into a static class and add the namespace to your view and you can use it.

There are plenty of examples online.

Justin

---

<div class="post-metadata">

**Author:** ![mistyn8](https://forum.umbraco.com/user_avatar/forum.umbraco.com/mistyn8/32/671_2.png) [@mistyn8](https://forum.umbraco.com/u/mistyn8)\
**Post date:** [September 11, 2026, 11:47am UTC](https://forum.umbraco.com/t/accessing-custom-image-properies-in-templates-via-modelsbuidler/8532/8 "2026-09-11T11:47:34Z")

</div>

nicer to add that extension method as @justin-nevitech says.. but you can also define functions in views (though not recommended with separation of concerns in MVC)

```csharp
@functions {
    void AltText(MediaWithCrops? media)
    {
         ....
   }
}

```

you could also have a centralised partial view for all your image rendering..

`<partial name="imagewithAltText" model="Image">`

or indeed a view component (more boilerplate to create)… if you needed to do something procedurally with it. or easily pass multiple params (though you can pass a view-data model into a partial too)  
`<partial name="blockgrid/bs_area" model="area" view-data='new ViewDataDictionary(ViewData) { { "bsBreakpointCols", bsBreakpointCols } }' />`

`<vc:my-view-component model="Model" offer-guid='Model.Parent()?.Key' />`

All depends on your use case and preference.

---

<div class="post-metadata">

**Author:** ![Eaglef90](https://forum.umbraco.com/user_avatar/forum.umbraco.com/eaglef90/32/1014_2.png) [@Eaglef90](https://forum.umbraco.com/u/Eaglef90)\
**Post date:** [September 11, 2026, 11:06pm UTC](https://forum.umbraco.com/t/accessing-custom-image-properies-in-templates-via-modelsbuidler/8532/9 "2026-09-11T23:06:59Z")

</div>

I got this setup and it works perfectly. Thank you very much for the help

---

<div class="post-metadata">

**Author:** ![system](https://forum.umbraco.com/uploads/default/original/1X/624adeddd330a3d0268a184db47946ca7e82c676.png) [@system](https://forum.umbraco.com/u/system)\
**Post date:** [November 10, 2026, 11:07pm UTC](https://forum.umbraco.com/t/accessing-custom-image-properies-in-templates-via-modelsbuidler/8532/10 "2026-11-10T23:07:35Z")

</div>

Closed on November 10, 2026, 11:07pm UTC

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
