Copied to clipboard

Flag this post as spam?

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


  • Mr A 216 posts 278 karma points
    Feb 04, 2013 @ 08:01
    Mr A
    0

    Using forloop to pass types of crop to img

    Hi ,

    I am trying to pass the crop which is saved i array to the image but its not working for some reason , any one knows where i am getting it wrong, below is the syntax:

    <div class="cover">
        @{  
            string[] cropBox = {"crop1","crop2" };
    
            foreach (var node in Model.Children)
            {
             dynamic croping = @node.mainImage.mediaItem.Image.crop;
                <p>@index</p>
                @croping;
                var t = cropBox[index];
    
            foreach (dynamic crops in croping)
             {  
    
              <img src="@crops.Find("@name","cropBox[index]").url" alt="" />
    
             }  
    
            index++;
    
            }</div> 
    @*Working syntax*@
    <img src="@crops.Find("@name","crop1").url" alt="" />
  • Mike Chambers 636 posts 1253 karma points c-trib
    Feb 04, 2013 @ 09:20
    Mike Chambers
    100

    Think as you have enclosed in a ".." you'll actually be passing cropBox[index] as plain text into the Find method.. (also you posted code references undeclared variables, indes and name...

    @{ string[] cropBox = {"crop1","crop2" }; int index = 0; string name = ""; foreach (var node in Model.Children) { dynamic croping = @node.mainImage.mediaItem.Image.crop; <p>@index</p> @croping; var t = cropBox[index]; foreach (dynamic crops in croping) { <img src="@crops.Find(name,cropBox[index]).url" alt="" /> } index++; }

     

Please Sign in or register to post replies

Write your reply to:

Draft