Copied to clipboard

Flag this post as spam?

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


  • Profiterole 232 posts 264 karma points
    Mar 12, 2012 @ 17:00
    Profiterole
    1

    if field is not empty

    Hi guys, i'm trying to display a field only if it's not empty. It works when not empty, but I got a macro error when empty. So, if in the foreach there's a result with empty "matiere", I got a error...

    What I do wrong?

    @foreach (var r in results.Skip(currentPage*10).Take(10))
        
    {            
     
                     <p>
                <a href="@umbraco.library.NiceUrl(r.Id)"><strong>@r.Fields["nodeName"]</strong></a><br />
                 <small>Matière : if(!String.IsNullOrEmpty(@r.Fields["matiere"])){@r.Fields["matiere"]}</small>   
           </p> 
    }

  • Profiterole 232 posts 264 karma points
    Mar 12, 2012 @ 18:37
    Profiterole
    1

    Ok, got it working :

    <small> - Matière : @if(r.Fields.Keys.Contains("matiere")){@r.Fields["matiere"]}</small> 
Please Sign in or register to post replies

Write your reply to:

Draft