Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • wolulcmit 357 posts 693 karma points
    Dec 02, 2014 @ 14:39
    wolulcmit
    0

    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:

    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&amp;width=200&amp;height=400&amp;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 :(

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 02, 2014 @ 17:18
    Jeavon Leopold
    0

    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:

    <img src="@(Model.Content.Image.Cropper.GetCropUrl(200,400))" alt="@image.Name"/>
    
  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 02, 2014 @ 17:20
    Jeavon Leopold
    1

    p.s. You can take only the parts of the Hybrid Framework for the default controller if you only want the output caching parts

  • wolulcmit 357 posts 693 karma points
    Dec 02, 2014 @ 20:18
    wolulcmit
    0

    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

  • wolulcmit 357 posts 693 karma points
    Dec 02, 2014 @ 22:05
    wolulcmit
    0

    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?

  • Tom Steer 161 posts 596 karma points
    Dec 02, 2014 @ 23:02
    Tom Steer
    1

    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

  • wolulcmit 357 posts 693 karma points
    Dec 02, 2014 @ 23:11
    wolulcmit
    0

    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

  • wolulcmit 357 posts 693 karma points
    Dec 02, 2014 @ 23:15
    wolulcmit
    0

    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

  • Tom Steer 161 posts 596 karma points
    Dec 02, 2014 @ 23:21
    Tom Steer
    0

    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

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 02, 2014 @ 23:23
    Jeavon Leopold
    100

    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?

  • wolulcmit 357 posts 693 karma points
    Dec 02, 2014 @ 23:31
    wolulcmit
    0

    @Tom, at the moment theres not much in my partial just so I can test

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    Model.Content.GetPropertyValue<Umbraco.Extensions.Models.Generated.Image>("test").Cropper.GetCropUrl(100,100)

    @Jeavon, great thanks watching it now.

    still cant get Model.Content.Test to work after a rebuild, but probably missing something

    - Tim

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 02, 2014 @ 23:36
    Jeavon Leopold
    0

    Did you install the Visual Studio Extension? There is also a whole uHangOut about only the Model Builder here

  • Tom Steer 161 posts 596 karma points
    Dec 02, 2014 @ 23:37
    Tom Steer
    1

    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)" />

  • wolulcmit 357 posts 693 karma points
    Dec 02, 2014 @ 23:47
    wolulcmit
    0

    @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.

  • Tom Steer 161 posts 596 karma points
    Dec 02, 2014 @ 23:57
    Tom Steer
    1

    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

  • wolulcmit 357 posts 693 karma points
    Dec 03, 2014 @ 00:32
    wolulcmit
    0

    @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)."

    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 :)

  • wolulcmit 357 posts 693 karma points
    Dec 03, 2014 @ 01:14
    wolulcmit
    0

    Hallelujah! finally got the ModelsBuilder working and now I can just use what Jeavon originally posted to get an image crop

    <imgsrc="@(Model.Content.Test.Cropper.GetCropUrl(200,400))"alt="@image.Name"/>

    Thanks both Jeavon and Tom!

  • wolulcmit 357 posts 693 karma points
    Dec 04, 2014 @ 12:41
    wolulcmit
    0

    Sorry this was posted incomplete the first time, below is the full post

  • wolulcmit 357 posts 693 karma points
    Dec 04, 2014 @ 12:59
    wolulcmit
    0

    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:

    @using Content = Umbraco.Extensions.Models.Generated.Home;
    @inherits Umbraco.Web.Mvc.UmbracoViewPage<MasterModel<Home>>

    @foreach (var item in Model.Content.Children)
    {
    <li><a href="@item.Url"><img src="@item.OverviewImage.Cropper.GetCropUrl(400,400)" alt="@item.Name"></a></li>
    }

     

    but how do you use Models other the one that you inherited from in the same way?
    For example:

    @using Content = Umbraco.Extensions.Models.Generated.Home;
    @inherits Umbraco.Web.Mvc.UmbracoViewPage<MasterModel<Home>>

    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.

    - Tim

     

     

Please Sign in or register to post replies

Write your reply to:

Draft