Hi @Kavya Kohli
How to fix 'System.NullReferenceException: Object reference not set to an instance of an object.' ?
Before using the foreach statement, you can add an If-Else statement to check whether the Model is null. Try to change the table body as below: if the model is null, it will show an "empty" in the table, otherwise display the records.
<tbody>
@if(Model == null)
{
<tr><td colspan="5" style="text-align:center">empty</td></tr>
}
else
{
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.FullName)
</td>
<td>
@Html.DisplayFor(modelItem => item.EmpCode)
</td>
<td>
@Html.DisplayFor(modelItem => item.Position)
</td>
<td>
@Html.DisplayFor(modelItem => item.OfficeLocation)
</td>
<td>
<a asp-action="AddOrEdit" asp-route-id="@item.EmployeeId"><i class="fa fa-marker fa-lg"></i></a>
<a asp-action="Delete" asp-route-id="@item.EmployeeId" class="text-danger ml-1" onclick="return confirm('Are you sure to delete this record?')"><i class="fa fa-trash-alt fa-lg"></i></a>
</td>
</tr>
}
}
</tbody>
Like this:

If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion