Copied to clipboard

Flag this post as spam?

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


  • Dennis M Dewey 15 posts 35 karma points
    Nov 08, 2011 @ 08:25
    Dennis M Dewey
    0

    Classic Image Array for a slideshow using Razor

    I cannot get this to work. It was constructed using the examples file in Umbraco 4.7.1. 

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using DigibizAdvancedMediaPicker
    @{  
        <ul>
            @foreach (dynamic media Model.MediaById(Model.HomePageSlideShow))
            {
                <li>
                    <img src="@media.umbracoFile" alt="@media.nodeName" />
               </li>
            }
        </ul>
    }

    This is the error that I'm getting :

    c:\HostingSpaces\xxx\xxx.com\wwwroot\macroScripts\634563041717224178_Slideshow.cshtml(6): error CS1515: 'in' expected

  • Dennis M Dewey 15 posts 35 karma points
    Nov 08, 2011 @ 08:46
    Dennis M Dewey
    0

    I should also add that this works like a charm. I just cannot figure out how to do an array. I set this up exactly the same as the first one except the DAMP data type is using a single media item.

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using DigibizAdvancedMediaPicker
    @{
    dynamic media = Model.MediaById(Model.HomePageSlideShow2);
    <img src="@media.umbracoFile" alt="@media.nodeName" width="800px"/>
    }
  • Jeroen Breuer 4861 posts 12136 karma points MVP 3x admin c-trib
    Nov 08, 2011 @ 09:23
    Jeroen Breuer
    0

    Isn't it just a typo? This is what you have:

    @foreach (dynamic media = Model.MediaById(Model.HomePageSlideShow))

    And I think it should be this:

    @foreach (dynamic media in Model.MediaById(Model.HomePageSlideShow))

    But even if you do that you are using Model.MediaById. Doesn't that always return 1 item so can you do a foreach on that?

    Here is the Razor code I used in the example. It's a bit different.

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using DigibizAdvancedMediaPicker;
    
    @{  
       //DAMP File
       dynamic file = Model.dampFile.mediaItem.File;
    
       <h3 style="margin-top: 20px;">Razor DAMP file sample</h3>
       <p>Download: <a href="@file.umbracoFile" target="_blank">@file.nodeName</a></p>
    
       //DAMP Classic
       dynamic media = Model.MediaById(Model.dampClassic);
    
       <h3 style="margin-top: 20px;">Razor DAMP classic sample</h3>
       <img src="@media.umbracoFile" alt="@media.nodeName" height="400px"/>
    
       <table>
           <tr>
               <td style="vertical-align: top; padding-right: 20px;">
    
                   @*DAMP New wide*@
                   <h3 style="margin-top: 20px;">Razor DAMP new wide sample</h3>
                   <ul>
                       @foreach (dynamic d in Model.dampNewWide)
                       {
                           <li>
                               <img src="@DAMP_Helper.GetImageCropperUrl(d, "wideCrop")" alt="@d.ImageWide.nodeName"/>
                           </li>
                       }
                   </ul>
    
               </td>
               <td  style="vertical-align: top;">
    
                   @*DAMP New long*@
                   <h3 style="margin-top: 20px;">Razor DAMP new long sample</h3>
                   <ul>
                       @foreach (dynamic d in Model.dampNewLong)
                       {
                           //Get the image (= MediaType ImageLong)
                           var imageLong = d.ImageLong;
    
                           //Get the crop (propertyName = longImage)
                           var crop = imageLong.longImage;
    
                           <li>
                               <img src="@crop.Find("@name", "longCrop").url" alt="@imageLong.nodeName"/>
                           </li>
                       }
                   </ul>
    
               </td>
           </tr>
       </table>
    }

    Jeroen

  • Jeroen Breuer 4861 posts 12136 karma points MVP 3x admin c-trib
    Nov 08, 2011 @ 09:27
    Jeroen Breuer
    0

    You could also have a look at the Cultiv Razor Examples project. It also has some nice DAMP examples.

    Jeroen

  • Dennis M Dewey 15 posts 35 karma points
    Nov 08, 2011 @ 16:18
    Dennis M Dewey
    0

    I changed the code to:


     <ul>
        @foreach (dynamic media in Model.MediaById(Model.HomePageSlideShow))
        {
            <li>
                <img src="@media.umbracoFile" alt="@media.nodeName" />
           </li>
        }
    </ul>
     
      
        dynamic media2 Model.MediaById(Model.HomePageSlideShow2);
        
        <img src="@media2.umbracoFile" alt="@media2.nodeName" width="800px"/>
     
     } 

    but that didn't work either. Now I'm getting this error on the actual page :

    Error loading Razor Script Slideshow.cshtml
    Cannot get MediaById without an id

    I'm using an id for the datatype, though. This seems like an error message that I'd only get from using full media xml in the datatype. I tried that just to see what would happen and I get this error :

    Error loading Razor Script Slideshow.cshtml
    Object reference not set to an instance of an object.

    I'm going to look more closely at the Cultiv Razor Examples. I just didn't recall seeing a useable example. I just want the classic to work as a multiple. I don't need to recrop the images.

  • Jeroen Breuer 4861 posts 12136 karma points MVP 3x admin c-trib
    Nov 08, 2011 @ 16:36
    Jeroen Breuer
    0

    If you only use the id and store multiple images the ids are stored in a csv format. For example the value may look like this: "1056,1089,1103". You first need to split the string, loop trough that and than use Model.MediaById. 

    For splitting the string you can do something like this:

    char[] splitChar = { ',' };
    string[] ids = Model.HomePageSlideShow.ToString().Split(splitChar, StringSplitOptions.RemoveEmptyEntries);

    @foreach (string id in ids )
    {
    //use Model.MediaById(id) and work with that. }

    Jeroen

  • Dennis M Dewey 15 posts 35 karma points
    Nov 08, 2011 @ 20:39
    Dennis M Dewey
    0

    I got it to work using the full xml in the datatype. Here is the code I'm using to extract the uncropped images :

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using DigibizAdvancedMediaPicker

    @{  
        if (Model.HasValue("HomePageSlideShow"){
            dynamic mediaItems Model.HomePageSlideShow.mediaItem;
            if (mediaItems.Count(!= 0)
            {
                <ul>
                @foreach (var item in mediaItems)
                {
                    var image item.Image;
                    <li>
                        <img src="@image.umbracoFile" alt="@image.nodeName" />
                    </li>
                }
                </ul>
            }
        }

    Thanks for your input, Jeroen. I don't think I would've figured it out unless I actually looked at the
    Cultiv Razor Examples. They proved to be more useful than I thought they would be.

  • shaheen 1 post 21 karma points
    Jun 25, 2015 @ 11:08
    shaheen
    0

    plz help me how to create slide image in umbraco 6.what is the steps?

Please Sign in or register to post replies

Write your reply to:

Draft