Copied to clipboard

Flag this post as spam?

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

  • ianhoughton 217 posts 362 karma points c-trib
    Mar 02, 2012 @ 14:42

    Image crop in Razor

    I've tried following the code snippet here but can't seem to get it working.

    My xml is like this:

    <FancyDressProduct id="1819" parentID="1742" level="5" writerID="0" creatorID="0" nodeType="1240" template="1057" sortOrder="1" createDate="2012-02-23T15:48:35" updateDate="2012-03-02T08:33:25" nodeName="Santa" urlName="santa" writerName="Ian Houghton" creatorName="Ian Houghton" path="-1,1073,1153,1178,1742,1819" isDoc="">
                  <crops date="02/03/2012 08:33:16">
                    <crop name="fancyDress" x="0" y="0" x2="400" y2="600" url="/media/21002/278_fancyDress.jpg" />
    <p><span>Large; Cotton santa jacket with white fur trim and
    trousers. Boot covers, wig 'n' beard, hat and gloves all
                <umbracoUrlName />
                <umbracoUrlAlias />
                <umbracoRedirect />

    and my razor code is:

    @inherits umbraco.MacroEngines.DynamicNodeContext
      var pagesToList = @Model.Children;
      // configuration
      var itemsPerPage = String.IsNullOrEmpty(Parameter.ItemsPerPage) ? 3 : int.Parse(Parameter.ItemsPerPage);
      var previousLabel = String.IsNullOrEmpty(Parameter.PreviousLabel) ? "Previous" : Parameter.PreviousLabel;
      var nextLabel = String.IsNullOrEmpty(Parameter.NextLabel) ? "Next" : Parameter.NextLabel;
      // paging calculations
      var numberOfItems = pagesToList.Count();
      int currentPage = 1;
      if (!int.TryParse(HttpContext.Current.Request.QueryString["Page"], out currentPage)) {
        currentPage = 1;
      var numberOfPages = numberOfItems % itemsPerPage == 0 ? Math.Ceiling((decimal)(numberOfItems / itemsPerPage)) : Math.Ceiling((decimal)(numberOfItems / itemsPerPage))+1; 
        Total Items: @numberOfItems <br />
        Items per Page: @itemsPerPage<br />
        Pages: @numberOfPages;<br />
        Current Page: @(currentPage)
      // Products List
      <ul class="productsLandscape">
        @foreach(var item in pagesToList.Skip(currentPage*itemsPerPage).Take(itemsPerPage))
           <a id="fancyDress" href="@item.umbracoFile">
               <img src="@item.crops.Find("@name","fancyDress").url" alt="" /> 
           <div class="fancyDressDetails left">
              <p>Reserve price: <b>£@item.reservePrice</b> (+ £20.00 deposit)</p>
              <p>Product code: <b>@item.productCode</b> (please quote in correspondence)</p>
              <p>Size: <b>@item.productSize</b></p>
              <input type="button" text="Reserve Item" />
          <div class="clear"></div>
          <div class="divider"></div>
      <p class="pagingPages">
      // Google style paging links
        if (currentPage > 0) {
          <a href="[email protected](currentPage)">&laquo; @previousLabel</a>
        } else {
          <span class="pagingDisabled">&laquo; @previousLabel</span>
        var Pages = Enumerable.Range(1, (int)numberOfPages);
        foreach(var number in Pages) {
          if (number-1 != currentPage) {
          <a href="[email protected]">@number</a>
          } else {
        if (currentPage < Pages.Count()-1) {
          <a href="[email protected](currentPage+2)">@nextLabel &raquo;</a>
        } else {
          <span class="pagingDisabled">@nextLabel &raquo;</span>

    but I'm getting this error:

    Error loading Razor Script FancyDressListing.cshtml
    'string' does not contain a definition for 'Find'

Please Sign in or register to post replies

Write your reply to: