Copied to clipboard

Flag this post as spam?

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


  • hetaurhet 245 posts 267 karma points
    Feb 21, 2012 @ 07:11
    hetaurhet
    0

    True/false propert access

    hello

    I have following code in razor...

    @using umbraco.BusinessLogic;
    @using umbraco.MacroEngines;
    @inherits umbraco.MacroEngines.DynamicNode
    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
      
      <div class="float:left;">
      
     
      @foreach(var item in Model.Parent.Children)
      {
        <a href="@item.Url">@item.Name</a><br />
      }
      </div>
      
      var nodes=@Model.Children;
       
       foreach(var node in nodes)
       {
         dynamic link = Library.MediaById(node.competitionThumbImage);
         if(@node.GetProperty("isFirst").Value.ToString() != null && @node.GetProperty("isFirst").Value.ToString() == "True")
         {
         <a href="@node.NiceUrl" target="_blank"><img src="@link.umbracoFile" alt="@node.PageHeading" title="@node.PageHeading" width="126" height="126"/></a><br />
         <p>1st Rank</p>
         }
         else
         {
          <a href="@node.NiceUrl" target="_blank"><img src="@link.umbracoFile" alt="@node.PageHeading" title="@node.PageHeading" width="126" height="126"/></a><br />
         }
       }
      
    }

    Which checks True/false type property 'isFirst' and if it is checked then shows '1st rank' text. But it is not showing even when it is checked. So what is wrong in this? also, no error is coming.

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Feb 21, 2012 @ 10:29
    Dan Diplo
    0

    You shouldn't need to convert a True/False property to string to evaluate it (and if you do I think they evaluate as "0" and "1"). Rather, treat them as bools. Also, as your nodes are of type Dynamic there is no need to use the long-winded GetProperty method. I think you should just be able to do this:

    if (@node.isFirst)
    {
    //
    }
    else
    {
    //
    }

     

     

     

     

  • hetaurhet 245 posts 267 karma points
    Feb 25, 2012 @ 05:14
    hetaurhet
    0

    thank you

Please Sign in or register to post replies

Write your reply to:

Draft