Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi,
I am trying to migrate a v7 to a v8 site. This code line does not work anymore. How do I that with Umbraco 8? It is a partialView used by many Docs, al of which have a property introImage.
@inherits Umbraco.Web.Mvc.UmbracoViewPage @{ var introImage = Umbraco.Media(Model.Value<string>("introImage")); } @if (introImage != null) { <img src="@introImage.GetCropUrl("2.5:1")" class="img-responsive" /> }
Kind regards, Stephan
With ModelsBuilder/strongly typed models and using composition (?) for the property you should be able to do:
@inherits Umbraco.Web.Mvc.UmbracoViewPage<INameOfComposition> @{ var introImage = Model.IntroImage; }
With Model.IntroImage giving you a Umbraco.Web.PublishedModels.Image.
Regards, Magnus
If you don't use ModelsBuilder, you can cast the value to an IPublishedContent to get the referenced media item.
IPublishedContent
@inherits Umbraco.Web.Mvc.UmbracoViewPage @{ var introImage = Model.Value<IPublishedContent>("introImage")); } @if (introImage != null) { <img src="@introImage.GetCropUrl("2.5:1")" class="img-responsive" /> }
/Bjarne
Thanks all
found out, that the error I ran into is described here: https://our.umbraco.com/forum/umbraco-8/97235-possible-caching-error-umbracowebpublishedmodelsimage
So, apprently not my old syntax was the reason, although it is good to know how to do a proper code for V8
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
Get Media UmbracoHelper V8
Hi,
I am trying to migrate a v7 to a v8 site. This code line does not work anymore. How do I that with Umbraco 8? It is a partialView used by many Docs, al of which have a property introImage.
Kind regards, Stephan
With ModelsBuilder/strongly typed models and using composition (?) for the property you should be able to do:
With Model.IntroImage giving you a Umbraco.Web.PublishedModels.Image.
Regards, Magnus
If you don't use ModelsBuilder, you can cast the value to an
IPublishedContent
to get the referenced media item./Bjarne
Thanks all
Hi,
found out, that the error I ran into is described here: https://our.umbraco.com/forum/umbraco-8/97235-possible-caching-error-umbracowebpublishedmodelsimage
So, apprently not my old syntax was the reason, although it is good to know how to do a proper code for V8
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.