using Umbraco.Core.Models;
using Umbraco.Core.Services;
But that did not help ?
Dave Woestenborghs:
Thankyou :-) I have not intentionally or knowingly used "Image cropper on your media item" . Note that and Umbraco BackOffice Media / Image /Properties shows Media Type as "Image".
The @Umbraco.Media comes from the Umbraco.Web.UmbracoHelper class. What does your view inherit from? In my example my view inherited UmbracoTemplatePage. Are you using a custom model? You should be able to find the solution on this documentation: https://our.umbraco.org/documentation/Reference/Querying/UmbracoHelper/
Ahhh I see ....... FYI ... my code is part of a uCommerce Helper created for WebForms but which I am using in a MVC app (although many of my pages are from the uCommerce code and do not follow MVC coding practice - those pages are typically included as partial views without models or controllers, not perfect but works). That (I think) is why I have not inherited from UmbracoTemplatePage. I resolved this from info on https://our.umbraco.org/documentation/Reference/Querying/UmbracoHelper/ with
var umbracoHelper = new Umbraco.Web.UmbracoHelper
So then coding as you suggested:
var umbracoHelper = new Umbraco.Web.UmbracoHelper(Umbraco.Web.UmbracoContext.Current);
var mediaItem = umbracoHelper.Media(product.ThumbnailImageMediaId);
string imageSource = (string) mediaItem.umbracoFile;
I got the error: "Cannot implicitly convert type 'Umbraco.Web.Models.ImageCropDataSet' to 'string' "
But with a minor modification using mediaItem.Url instead of mediaItem.umbracoFile it all works:
var umbracoHelper = new Umbraco.Web.UmbracoHelper (Umbraco.Web.UmbracoContext.Current);
var mediaItem = umbracoHelper.Media(product.ThumbnailImageMediaId);
// string imageSource = (string) mediaItem.umbracoFile;
string imageSource = (string)mediaItem.Url;
Thanks for your assistance resolving this. It is still unclear why this happened as this code previously worked. I suspect a breaking change in recent versions of Umbraco? Anyway all good now, thanks very much Denis.
Umbraco dynamic mediaItem url property has extra unwanted charaters in the string
Hi all,
The following code:
Sets imageSource to
But if the html img tag is to work, it should be just the path as follows:
without the extra ""{src:" at the beginning and ", crops: []}"" at the end.
Can anyone please help me understand what is happening and/or how to fix it ?
Thanks very much
Terry Clancy
ClanceZ
Try this:
Hi,
Looking at this you are using the image cropper on your media item.
You can do
To display a image of 100x100
Dave
Dave and Dennis,
Thanks very much ... FYI I am using Umbraco version 7.4.1
Dennis Adolfi:
Thankyou. Trying to use code you suggest:
On Umbraco.Media I get
"The type or namespace media does not exist in the namespace Umbraco, (are you missing an assembly reference?).
What DLL do I need to reference please - based on https://our.umbraco.org/Documentation/Reference/Management/Models/Media I tried to reverence Umbraco.Core.DLL and added
But that did not help ?
Dave Woestenborghs:
Thankyou :-) I have not intentionally or knowingly used "Image cropper on your media item" . Note that and Umbraco BackOffice Media / Image /Properties shows Media Type as "Image".
When I try to include the code you suggest:
imageSource returns an empty string ?? Also using debugger mediaItem does not show a property or method "GetCropUrl" ??
Any help with either of these two approaches to solve the problem would be appreciated.
Terry Clancy
ClanceZ
The
@Umbraco.Media
comes from theUmbraco.Web.UmbracoHelper
class. What does your view inherit from? In my example my view inherited UmbracoTemplatePage. Are you using a custom model? You should be able to find the solution on this documentation: https://our.umbraco.org/documentation/Reference/Querying/UmbracoHelper/Hi Denis and THANKs again.
Ahhh I see ....... FYI ... my code is part of a uCommerce Helper created for WebForms but which I am using in a MVC app (although many of my pages are from the uCommerce code and do not follow MVC coding practice - those pages are typically included as partial views without models or controllers, not perfect but works). That (I think) is why I have not inherited from UmbracoTemplatePage. I resolved this from info on https://our.umbraco.org/documentation/Reference/Querying/UmbracoHelper/ with
So then coding as you suggested:
I got the error: "Cannot implicitly convert type 'Umbraco.Web.Models.ImageCropDataSet' to 'string' "
But with a minor modification using mediaItem.Url instead of mediaItem.umbracoFile it all works:
Thanks for your assistance resolving this. It is still unclear why this happened as this code previously worked. I suspect a breaking change in recent versions of Umbraco? Anyway all good now, thanks very much Denis.
Terry Clancy
ClanceZ
Perfect, glad to hear that it worked out for you Terry!
Much appriciated if you would mark my post as solution.
Have as great night!
Thanks again and will do !!
Terry Clancy
ClanceZ
is working on a reply...