Marius Vasile

Marius Vasile

  • 590
  • 1.9k
  • 146.2k

asp.net core error on int null

Sep 2 2021 6:21 PM

I want to be able to show data if an integer is not null. However, if is null I get error

@if (item.PTWSubsequent.PTWNoS != 0)
   {
     <div class="col-md-1">
       <a class="form-control text-center btn-link" asp-page="/PTW/IsolationCertificate" asp-route-ptwid="@item.PTWId" asp-route-ptwsid="@item.PTWSId">@Html.DisplayFor(model => item..PTWNoS)</a>
     </div>
   }

and code behind

PTWContentList = await _context.PTWContents.Include(s => s.PTWMain).Include(s => s.PTWSubsequent).Where(s => s.PTWMain.OrgID == orgid).ToListAsync();

I get the error that PTWNoS is null which I know is null. I just want to not show the div if is null


Answers (5)