5
Answers

asp.net core error on int null

Marius Vasile

Marius Vasile

3y
548
1

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)