Copied to clipboard

Flag this post as spam?

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


  • Kasper Dyrvig 246 posts 379 karma points
    May 31, 2012 @ 08:37
    Kasper Dyrvig
    0

    Find an error: Looping media items

    I'm trying to loop through media items in a media folder. I have succeeded by using the macro template for doing just that. But when I add a <ul> to present the items in a list I get this error: "No overload for method 'Write' takes 0 arguments'."

    Why? What went wrong? Any help is appreciated.

    This is my razor code:

    @{    
        @* Get the macro parameter and check it has a value otherwise set to empty hive Id *@
        var mediaFolderID = String.IsNullOrEmpty(Model.MacroParameters.mediaFolderID) ? HiveId.Empty.ToString() : Model.MacroParameters.mediaFolderID;
    }
    @if (mediaFolderID != HiveId.Empty.ToString() && HiveId.TryParse(mediaFolderID).Success)
    {
      var mediaFolder = Umbraco.GetDynamicContentById(mediaFolderID);
      
      if (mediaFolder.Children.Any())
        {
          <ul>
            @foreach (var mediaItem in mediaFolder.Children)
            {
              @{var fileURL = Umbraco.GetMediaUrl(mediaItem.Id, "uploadedFile");}
              <li><p><strong><a href="@fileURL" title="@mediaItem.Name">@mediaItem.Name</a></strong><br /><span class="subPageDate">Sidst opdateret @mediaItem.UpdateDate.ToString("dd/MM/yyyy hh:mm")</span><br />@mediaItem.fileDescription</p></li>
            }
          </ul>
        }
    }

     

  • gilad 185 posts 425 karma points
    May 31, 2012 @ 08:40
    gilad
    0

    Hii kasper

    try remove the @ from this line :

    @{var fileURL =Umbraco.GetMediaUrl(mediaItem.Id,"uploadedFile");} 

    like this:

    var fileURL =Umbraco.GetMediaUrl(mediaItem.Id,"uploadedFile");

     

  • Grant Thomas 291 posts 324 karma points
    May 31, 2012 @ 10:29
    Grant Thomas
    1

    Kasper, I agree with gilad on what this looks like. Try this:

     

    @{
      @* Get the macro parameter and check it has a value otherwise set to empty hive Id *@
      var mediaFolderID = String.IsNullOrEmpty(Model.MacroParameters.mediaFolderID) ?
        HiveId.Empty.ToString() : Model.MacroParameters.mediaFolderID;
      if (mediaFolderID != HiveId.Empty.ToString() && HiveId.TryParse(mediaFolderID).Success) {
        var mediaFolder = Umbraco.GetDynamicContentById(mediaFolderID);
        if (mediaFolder.Children.Any()) {
          <ul>
          @foreach (var mediaItem in mediaFolder.Children) {
            var fileURL = Umbraco.GetMediaUrl(mediaItem.Id, "uploadedFile");
              <li>
                <p>
                  <strong>
                    <a href="@fileURL" title="@mediaItem.Name">@mediaItem.Name</a>
                  </strong>
                  <br />
                  <span class="subPageDate">Sidst opdateret @mediaItem.UpdateDate.ToString("dd/MM/yyyy hh:mm")</span>
                  <br />@mediaItem.fileDescription
                </p>
              </li>
          }
        </ul>
        }
      }
    }

     

  • Kasper Dyrvig 246 posts 379 karma points
    May 31, 2012 @ 10:50
    Kasper Dyrvig
    0

    Hi guys

    Yes, that works perfect! (exept that you Grant had one } to much :-) )

    Thanks for your quick help

Please Sign in or register to post replies

Write your reply to:

Draft