Copied to clipboard

Flag this post as spam?

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


  • Anthony Candaele 1197 posts 2049 karma points
    May 14, 2012 @ 10:44
    Anthony Candaele
    0

    how to check for documenttype property on a dynamic type

    Hi,

    Currently I'm struggling to check if a documenttype (member) has a 'damp' image property:

     

    @{
      var membersToList @Model.Children.Where("Visible");
        <table>
        @foreach (var memberGroup in membersToList.InGroupsOf(3))
          {
           <tr>
           @foreach (dynamic member in memberGroup)
             {
              <td style="padding:10px;">
                  @{
                      if(member.HasValue("memberImage"))
                      {
                          var image member.memberImage.mediaItem.MemberImage.umbracoFile;
                      }
                   }
                @if (image != null)
                {
                    <img src="/imageGen.ashx?image=@image&amp;width=150" style="margin-bottom:10px;"/><br />
                    
                }
                else
                {
                    <img src="/imageGen.ashx?image=/media/1591/mystery-person.jpg&amp;width=150" style="margin-bottom:10px;"/><br />
                }           
                @(member.memberFirstName " " member.memberLastName
              </td>
             }
           </tr>
          }
            </table>
      }

    The problem is that I don't have any method on a dynamic type to check for the existence of a documenttype property. So I can't do for instance: if (member.HasValue("memberImage").Value != ""))

    Does anyone know I solution for this?

    Thanks for your help,
    Anthony

  • Anthony Candaele 1197 posts 2049 karma points
    May 14, 2012 @ 11:51
    Anthony Candaele
    0

    I found the solution, this works:

    @{
        var membersToList @Model.Children.Where("Visible");
        <table>
        @foreach (var memberGroup in membersToList.InGroupsOf(3))
        {
           <tr>
           @foreach (dynamic member in memberGroup)
           {
              <td style="padding:10px;">
              
                @
                    var image "";
                    if(member.memberImage.ToString(!= "")
                    {
                       image member.memberImage.mediaItem.MemberImage.umbracoFile;
                    }
                }
               
                   
                @if (image != "")
                {
                    <img src="/imageGen.ashx?image=@image&amp;width=150" style="margin-bottom:10px;"/><br />
                    
                }
                else
                {
                    <img src="/imageGen.ashx?image=/media/1591/mystery-person.jpg&amp;width=150" style="margin-bottom:10px;"/><br />
                }           
                @(member.memberFirstName " " member.memberLastName
              </td>
           }
           </tr>
        }
            </table>
      }

    greetings,

    Anthony

Please Sign in or register to post replies

Write your reply to:

Draft