Copied to clipboard

Flag this post as spam?

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


  • ianhoughton 281 posts 605 karma points c-trib
    Mar 02, 2012 @ 14:42
    ianhoughton
    0

    Image crop in Razor

    I've tried following the code snippet here https://gist.github.com/1170848 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="">
                <productTitle>Santa</productTitle>
                <crops>
                  <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" />
                  </crops>
                </crops>
                <productDetails><![CDATA[
    <p><span>Large; Cotton santa jacket with white fur trim and
    trousers. Boot covers, wig 'n' beard, hat and gloves all
    included.</span></p>
    ]]></productDetails>
                <productCode>C-01</productCode>
                <reservePrice>25</reservePrice>
                <deposit>25</deposit>
                <productSize>Large</productSize>
                <featuredProduct>0</featuredProduct>
                <umbracoFile>/media/21002/278.jpg</umbracoFile>
                <metaTitle><![CDATA[]]></metaTitle>
                <metaDescription><![CDATA[]]></metaDescription>
                <metaKeywords><![CDATA[]]></metaKeywords>
                <umbracoUrlName />
                <umbracoUrlAlias />
                <umbracoRedirect />
                <umbracoNaviHide>0</umbracoNaviHide>
              </FancyDressProduct>

    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;
      }
      currentPage--;
      var numberOfPages = numberOfItems % itemsPerPage == 0 ? Math.Ceiling((decimal)(numberOfItems / itemsPerPage)) : Math.Ceiling((decimal)(numberOfItems / itemsPerPage))+1; 
    
      <p>
        Total Items: @numberOfItems <br />
        Items per Page: @itemsPerPage<br />
        Pages: @numberOfPages;<br />
        Current Page: @(currentPage)
      </p>
    
      // Products List
      <ul class="productsLandscape">
        @foreach(var item in pagesToList.Skip(currentPage*itemsPerPage).Take(itemsPerPage))
        {
          <li>
           <a id="fancyDress" href="@item.umbracoFile">
               <img src="@item.crops.Find("@name","fancyDress").url" alt="" /> 
           </a>
           <div class="fancyDressDetails left">
              <h3>@item.Name</h3>
              <p>@item.productDetails</p>
              <br/>
              <br/>
              <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>
          <div class="clear"></div>
          <div class="divider"></div>
        </li>
        }
      </ul>
    
      <p class="pagingPages">
        @{
      // Google style paging links
        if (currentPage > 0) {
          <a href="?page=@(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="?page=@number">@number</a>
          } else {
          @number
          }
          @Html.Raw("&nbsp&nbsp");
        }
    
        if (currentPage < Pages.Count()-1) {
          <a href="?page=@(currentPage+2)">@nextLabel &raquo;</a>
        } else {
          <span class="pagingDisabled">@nextLabel &raquo;</span>
        }
      }
      </p>
    }

    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:

Draft