Copied to clipboard

Flag this post as spam?

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


  • Mikkel B. Mikkelsen 52 posts 81 karma points
    Jan 25, 2013 @ 09:31
    Mikkel B. Mikkelsen
    0

    Problem getting crops using RazorModel

    For some reason the DAMP_Item's Crops and TypedCrops properties throws a nullreference exception, even though the crops are in the XML. Here's a sample of the XML.

    <articleImage>
    <DAMP fullMedia="">
    <mediaItem>
    <Image id="1140" version="db73b6c8-fad4-40b5-9645-b90aaab6bae3" parentID="1123" level="2" writerID="0" nodeType="1032" template="0" sortOrder="0" createDate="2012-12-19T10:36:19" updateDate="2013-01-25T09:37:48" nodeName="image" urlName="image" writerName="admin" nodeTypeAlias="Image" path="-1,1123,1140">
    <umbracoFile>/media/772/image.png</umbracoFile>
    <umbracoWidth><![CDATA[]]></umbracoWidth>
    <umbracoHeight><![CDATA[]]></umbracoHeight>
    <umbracoBytes><![CDATA[]]></umbracoBytes>
    <umbracoExtension><![CDATA[]]></umbracoExtension>
    <crop>
    <crops date="2013-01-25T09:29:04">
    <crop name="ArticleTop" x="0" y="28" x2="918" y2="546" url="/media/772/image_ArticleTop.jpg" />
    <crop name="ArticleTopSplitLeft" x="0" y="14" x2="918" y2="560" url="/media/772/image_ArticleTopSplitLeft.jpg" />
    <crop name="ArticletopSplitRight" x="228" y="0" x2="689" y2="575" url="/media/772/image_ArticletopSplitRight.jpg" />
    <crop name="test" x="172" y="0" x2="747" y2="575" url="/media/772/image_test.jpg" />
    </crops>
    </crop>
    </Image>
    </mediaItem>
    </DAMP>
    </articleImage>

    And here's a sample of the razor code being used, and also the error message.

        foreach(var d in Model.articleImage)
    {
    <h1>@d.Crops.test.url</h1>
    }
       Error Loading Razor Script (file: Article With Image Content) Object reference not set to an instance of an object.    at DAMP.RazorModel.DAMP_Item.get_Crops()
    at CallSite.Target(Closure , CallSite , Object )
    at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
    at ASP._Page_macroScripts_ArticleWithImageContent_cshtml.Execute() in c:\Work\Mercurial Repos\Louis Poulsen\Umbraco\Umbraco.Site\MacroScripts\ArticleWithImageContent.cshtml:line 7
    at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
    at System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors)
    at System.Web.WebPages.WebPage.ExecutePageHierarchy()
    at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
    at umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage)
    at umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage)

    Here's the object as seen through visual studio.

    Running umbraco 4.11.1, DAMP 2.0, DAMP Razor Model 1.2

     

  • Mikkel B. Mikkelsen 52 posts 81 karma points
    Jan 25, 2013 @ 09:33
    Mikkel B. Mikkelsen
    0

    Welp, forgot the image. Editing your post apparently doesn't work.

    http://imgur.com/9j3ZduV

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jan 25, 2013 @ 13:16
    Jeroen Breuer
    1

    Hello,

    I already see the problem, but you couldn't know that ;-). When I fetch the crops I do this with an Xpath and I search for the first element named "crop" I find. Normally it would find this piece of xml:

    <crop name="ArticleTop" x="0" y="28" x2="918" y2="546" url="/media/772/image_ArticleTop.jpg" />

    But you named your Image Cropper property on the Media Type also crop so now this is the xml it will find:

    <crop>

    Just rename the alias of the Image Cropper datatype to something other than "crop" and it should be fixed just like I said here ;-). After you've done this you'll need to resave the media items because otherwise the xml is not updated. After that it should work :-).

    Jeroen

  • Craig100 1136 posts 2523 karma points c-trib
    Mar 10, 2013 @ 16:09
    Craig100
    0

    I'm having a similar problem (I think) with umb 6.0.2 and a Razor macro.

    I have a page with a DAMP that has 3 images in it.  I've used Jeroen's method of creating a special Media Type and Crop Data Type and DAMP Data Type for it. I can upload images as the correct Media Type and I can set and save the crop in the UI preview. All very nice.

    In the XML tree I can see the images saved as shown below. The DAMP media picker is called "sideImages":-

    <root id="-1">
     <Home id="1057" parentID="-1" level="1" creatorID="0" sortOrder="0" createDate="2013-03-08T19:39:48" updateDate="2013-03-10T14:55:27" nodeName="Home" urlName="home" path="-1,1057" isDoc="" nodeType="1055" creatorName="admin" writerName="admin" writerID="0" template="1054">
       <sideImages>1125,1127,1128</sideImages>
       <imageCredits><![CDATA["The Fat Lady Sings in
    Little Grimley" and
    "Round the Horne - Back Again!"
    performed in April 2012]]></imageCredits>
       <includeInMainNav>1</includeInMainNav>
       <includeInFooterNav>0</includeInFooterNav>
       <keywords />
       <pageTitle><![CDATA[]]></pageTitle>
       <description><![CDATA[]]></description>
     

    In the macro to display the three images I've tried:-

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
    DAMP.PropertyEditorValueConverter.Model mediaItems = new DAMP.PropertyEditorValueConverter.Model(Model.GetPropertyValue("sideImages"));
        foreach(dynamic item in mediaItems)
    {
    <img src="@item.File" alt="@item.Alt">
    }
    }

    This displays the files at full size, not the crops. So I've tried <img src="@item.Crops["crop"]" alt="@item.Alt"> and <img src="@item.TypedCrops["Right Hand Image"]" alt="@item.Alt"> but both break the macro when run. These are the values in the DAMP Data Type being used in the "Dsiplay Options" for the Image Cropper Property Alias and Crop Name.

    How do I get the crop?

    Craig

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Mar 11, 2013 @ 12:52
    Jeroen Breuer
    0

    You're storing the values as id's so I can't see how the media xml looks like.

    It also looks like you're using the DAMP Property Editor Value Converter in a Razor macro instead of MVC. More info about that here: http://our.umbraco.org/projects/backoffice-extensions/digibiz-advanced-media-picker/digibiz-advanced-media-picker/38888-Nothing-Seems-to-Work!#comment141954

    You could try the DAMP gallery for a good example.

    Jeroen

  • Craig100 1136 posts 2523 karma points c-trib
    Mar 11, 2013 @ 13:10
    Craig100
    0

    Thanks Jeroen.  I agree with Nick's comments on the "Nothing seems to work" post. I installed the DAMP Property Editor Value Convertor in error as well.

    Thanks for the DAMP Gallery pointer, I'll take a look at it now.

    Craig

Please Sign in or register to post replies

Write your reply to:

Draft