Copied to clipboard

Flag this post as spam?

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

  • ianhoughton 190 posts 323 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="?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 {
        if (currentPage < Pages.Count()-1) {
          <a href="?page=@(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:

Draft is the community mothership for Umbraco, the open source cms. With a friendly forum for all your questions, a comprehensive documentation and a ton of packages from the community. This site is running Umbraco version 7.3.1