-1

I try to do something like that. When my employee does not have a particular value that it is not displayed. I tried to do it like this:

    @foreach (var item in Model)
    {
        if (!item.Przewodnik.Uprawnienia.IsNullOrWhiteSpace()) { 
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.Przewodnik.Pracownik.Osoba.Imie)
                </td> 
                    (...)

But it give me a .NullReferenceException.

if(item.Przewodnik.Uprawnienia != null){...}

I tried this as well, but also give error.

TjDillashaw
  • 787
  • 1
  • 12
  • 29
  • 2
    Debug your code! Possibly `Przewodnik` is `null` –  Jun 22 '15 at 12:18
  • 1
    those who down vote should leave a comment explaining why so the question poster can improve whatever the down vote is meant to point out. Constructive feedback will help build somebody up which I believe is what SO strives for! – Leo Nix Jun 22 '15 at 12:30

1 Answers1

2

Try the following:

@foreach (var item in Model)
    {
        if (item != null && item.Przewodnik != null && !string.IsNullOrEmpty(item.Przewodnik.Uprawnienia)) { 
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.Przewodnik.Pracownik.Osoba.Imie)
                </td> 
                    (...)
Ala
  • 1,505
  • 1
  • 20
  • 36