Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Hi,
Have you tried using something like Html.PropertyFor(x => x.MainImage) to display the image instead?
I would recommend creating a Html helper function for this that you can reuse throughout your project(s):
public static class MediaHelpers { public static string GetImageVaultMediaUrl<T>(this HtmlHelper<T> html, Expression<Func<T, MediaReference>> expression) { var modelMetadata = ModelMetadata.FromLambdaExpression(expression, html.ViewData); var mediaReference = modelMetadata.Model as MediaReference; var settings = ServiceLocator.Current.GetInstance<PropertySettingsResolver>().GetSettings(typeof(PropertyMediaSettings), modelMetadata.ModelType, modelMetadata.PropertyName) as PropertyMediaSettings; var client = ClientFactory.GetSdkClient(); var media = client.Load<Thumbnail>(mediaReference, settings).FirstOrDefault(); return media?.Url; } }
And then call it like this whenever you need the URL:
<header style="background-image: url('@Html.GetImageVaultMediaUrl(m => m.HeaderImage)');">
Best regards,
Robert
ImageVault
Hello,
I have a view that use MainImage as a background. Recenly I have changed type of MainImage from ContentReference to MediaReference, because my client prefer to use the ImageVault. Now I got compile error becuuse MainImage is not type of ContentReference.
Does anyone know how to get ImageVault as an url background image?
Thanks,
/Katharina