Am using the latest Hybrid framework here, main just for donut caching, as Strongly Typed queries are just confusing to me. anyway that aside.
in previous v7 projects I've been able to get crop urls like this:
var imgId = Convert.ToInt32(fieldset.GetValue("Image")); var dynamicMediaItem = Umbraco.TypedMedia(imgId); <img src="@dynamicMediaItem.GetCropUrl(200,400)"/>
but that is returning me this <img src="Umbraco.Web.Models.ImageCropDataSet?mode=pad&width=200&height=400&rnd=130619825730000000">
any ideas what I'm doing wrong? and how to get the right data from Umbraco.Web.Models.ImageCropDataSet ?
thanks for any help, have spent way too much time on this :(
Something is strange here though. lets say my Imges's property alias is just called "test" Model.Content.Test gives me the error: error CS1061: 'Umbraco.Core.Models.IPublishedContent' does not contain a definition for 'Test' and no extension method 'Test' accepting a first argument of type 'Umbraco.Core.Models.IPublishedContent' could be found
where as CurrentPage.Test gives me: Umbraco.Extensions.Models.Generated.Image and CurrentPage.Test.Cropper gives me the url: /media/1005/02-img_5867.jpg but CurrentPage.Test.Cropper.GetCropUrl(200,400) gives me the error: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: The best overloaded method match for 'Umbraco.Web.Models.ImageCropDataSet.GetCropUrl(string, bool, bool, string)' has some invalid arguments
why does Model.Content.Test not work, and is this the sorce of all my problems?
@Model.Content.GetPropertyValue("test") also gives me: Umbraco.Extensions.Models.Generated.Image, but @Model.Content.GetPropertyValue("test").Cropper gives the error: error CS1061: 'object' does not contain a definition for 'Cropper' and no extension method 'Cropper' accepting a first argument of type 'object' could be found
so very confused. P.S in Hybrid framework is there an easy way to output the errors on the error page template so you dont need to keep going into the log file to see what went wrong?
I also get the error: 'Umbraco.Web.Models.ImageCropDataSet' does not contain a definition for 'GetResponsiveCropUrl' when trying to use Cropper.GetResponsiveCropUrl(50, 40) if that helps?
Hey Tim... Have you ran the Zbu Model Builder again since adding new doctypes/properties as if you haven't then the Test property might not actually exist on the current PublishedContentModel.
However you should also be able to do this without running the Model Builder again with the following:
I wasnt working out of visual studio so wasnt building the project (and was unaware of Zhu Model Builder), so that would probably explain Test not being on the PublishContentModel. However as above I still have this error when I try to use the cropper as you suggested: Model.Content.GetPropertyValue("test").Cropper.GetCropUrl(100,100) error CS1061: 'object' does not contain a definition for 'Cropper' and no extension method 'Cropper' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
Now gives me this error CS1502: The best overloaded method match for 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' has some invalid arguments
That does like it should work, but really you should use Visual Studio and the model builder if you are using the Hybrid Framework v7. Have you watched the Hybrid Framework v7 uHangout?
Wrap it in an image tag then it should work
<img src="@Model.Content.GetPropertyValue<Umbraco.Extensions.Models.Generated.Image>("test").Cropper.GetCropUrl(100,100)" />
@Tom still no dice when wrapped in an img tag.... different error though error CS1502: The best overloaded method match for 'System.Tuple.Create<object,int>(object, int)' has some invalid arguments
@Jeavon, thanks installed the ModelsBuilder tool in VS and think I have set it up correctly ,but when I right click Builder.cs and choose "run custom tool" i get this error:
ZbuModelsBuilder: ZbuModelsBuilder failed to generate code: Exception: Response status code does not indicate success (Forbidden) "API version conflict: client version (0.0.0.0) is not compatible with server version(2.0.0.26)."
have tried to upgrade it but didnt seem to work. hopefully will be able to upgrade it through a nuget command when it become available.
@Tom, thanks added a @using Umbraco.Extensions.Utilities but still the same error. will have to forgoe using any image crops for now so I can get some work done :)
var newsNode = Model.Content.AncestorOrSelf(3).Descendants("News").FirstOrDefault(); foreach(var newsItem in newsNode.Children.Take(2)){ { <li><a href="@newsItem.Url"><img src="@newsItem.OverviewImage.Cropper.GetCropUrl(400,400)" alt="@newsItem.Name"></a></li> }
The above wont work as it needs to inherit from that Model directly in order for the Generated Models to work properly. it will give you an error like: 'Umbraco.Core.Models.IPublishedContent' does not contain a definition for OverviewImage
Images seem to be particularly tricky to use in the default way as regular Model.Content.GetPropertyValue("image") returns a Umbraco.Extensions.Models.Generated.Image... and I'm not sure how to work with that.
hope that makes sense to someone... I'm sure I'm not explaining it that well.
Image crop Url problems in v7.19
Am using the latest Hybrid framework here, main just for donut caching, as Strongly Typed queries are just confusing to me. anyway that aside.
in previous v7 projects I've been able to get crop urls like this:
but that is returning me this
<img src="Umbraco.Web.Models.ImageCropDataSet?mode=pad&width=200&height=400&rnd=130619825730000000">
any ideas what I'm doing wrong? and how to get the right data from Umbraco.Web.Models.ImageCropDataSet ?
thanks for any help, have spent way too much time on this :(
Ah ok, as you are using the model builder to generate strongly typed models, you do not need to be doing all that conversion.
Should be something like this:
p.s. You can take only the parts of the Hybrid Framework for the default controller if you only want the output caching parts
Thanks Jeavon.
Something is strange here though.
lets say my Imges's property alias is just called "test"
Model.Content.Test gives me the error:
error CS1061: 'Umbraco.Core.Models.IPublishedContent' does not contain a definition for 'Test' and no extension method 'Test' accepting a first argument of type 'Umbraco.Core.Models.IPublishedContent' could be found
where as
CurrentPage.Test gives me:
Umbraco.Extensions.Models.Generated.Image
and CurrentPage.Test.Cropper gives me the url:
/media/1005/02-img_5867.jpg
but CurrentPage.Test.Cropper.GetCropUrl(200,400) gives me the error:
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: The best overloaded method match for 'Umbraco.Web.Models.ImageCropDataSet.GetCropUrl(string, bool, bool, string)' has some invalid arguments
why does Model.Content.Test not work, and is this the sorce of all my problems?
@Model.Content.GetPropertyValue("test") also gives me:
Umbraco.Extensions.Models.Generated.Image, but
@Model.Content.GetPropertyValue("test").Cropper gives the error:
error CS1061: 'object' does not contain a definition for 'Cropper' and no extension method 'Cropper' accepting a first argument of type 'object' could be found
so very confused.
P.S in Hybrid framework is there an easy way to output the errors on the error page template so you dont need to keep going into the log file to see what went wrong?
thanks again
- Tim
I also get the error: 'Umbraco.Web.Models.ImageCropDataSet' does not contain a definition for 'GetResponsiveCropUrl'
when trying to use Cropper.GetResponsiveCropUrl(50, 40) if that helps?
Hey Tim... Have you ran the Zbu Model Builder again since adding new doctypes/properties as if you haven't then the Test property might not actually exist on the current PublishedContentModel.
However you should also be able to do this without running the Model Builder again with the following:
Model.Content.GetPropertyValue<Umbraco.Extensions.Models.Generated.Image>("test").Cropper.GetCropUrl(100,100)
Tom
Hey Tom Thanks for the heads up,
I wasnt working out of visual studio so wasnt building the project (and was unaware of Zhu Model Builder), so that would probably explain Test not being on the PublishContentModel.
However as above I still have this error when I try to use the cropper as you suggested:
Model.Content.GetPropertyValue("test").Cropper.GetCropUrl(100,100)
error CS1061: 'object' does not contain a definition for 'Cropper' and no extension method 'Cropper' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
thanks,
- Tim
hey did you just edit your reply :)
Model.Content.GetPropertyValue<Umbraco.Extensions.Models.Generated.Image>("test").Cropper.GetCropUrl(100,100)
Now gives me this error CS1502: The best overloaded method match for 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' has some invalid arguments
Yeah it seemed to strip out part of it unless I put it in a code block. Are you able to post the contents of your view or partial view?
Cheers Tom
That does like it should work, but really you should use Visual Studio and the model builder if you are using the Hybrid Framework v7. Have you watched the Hybrid Framework v7 uHangout?
@Tom, at the moment theres not much in my partial just so I can test
@Jeavon, great thanks watching it now.
still cant get Model.Content.Test to work after a rebuild, but probably missing something
- Tim
Did you install the Visual Studio Extension? There is also a whole uHangOut about only the Model Builder here
Wrap it in an image tag then it should work
<img src="@Model.Content.GetPropertyValue<Umbraco.Extensions.Models.Generated.Image>("test").Cropper.GetCropUrl(100,100)" />
@Tom still no dice when wrapped in an img tag....
different error though
error CS1502: The best overloaded method match for 'System.Tuple.Create<object,int>(object, int)' has some invalid arguments
@Jeavon am just using the default Hybrid framework from here: https://github.com/jbreuer/Hybrid-Framework-for-Umbraco-v7-Clean
ran the project and Nuget grabbed all the dependencies it needed.
Might need to add a using statement to your view for the extensions class in hybrid framework:
Umbraco.Extensions.Utilities
Only on my iPhone so can't really look into it that far.
Cheers,
Tom
@Jeavon, thanks installed the ModelsBuilder tool in VS and think I have set it up correctly ,but when I right click Builder.cs and choose "run custom tool" i get this error:
which looks like other people have also hit this issue:
http://our.umbraco.org/projects/developer-tools/hybrid-framework-for-umbraco-v7/anything/58147-Zbu-ModelsBuilder-API-version-conflict
have tried to upgrade it but didnt seem to work. hopefully will be able to upgrade it through a nuget command when it become available.
@Tom, thanks added a @using Umbraco.Extensions.Utilities but still the same error. will have to forgoe using any image crops for now so I can get some work done :)
Hallelujah! finally got the ModelsBuilder working and now I can just use what Jeavon originally posted to get an image crop
Thanks both Jeavon and Tom!
Sorry this was posted incomplete the first time, below is the full post
Sorry to post back to this topic but have some questions about Hybrid framework that I just cant figure out.
you can do something like this:
but how do you use Models other the one that you inherited from in the same way?
For example:
The above wont work as it needs to inherit from that Model directly in order for the Generated Models to work properly.
it will give you an error like: 'Umbraco.Core.Models.IPublishedContent' does not contain a definition for OverviewImage
Images seem to be particularly tricky to use in the default way as regular Model.Content.GetPropertyValue("image") returns a Umbraco.Extensions.Models.Generated.Image... and I'm not sure how to work with that.
hope that makes sense to someone... I'm sure I'm not explaining it that well.
- Tim
is working on a reply...