При удалении записи в ASP.NET MVC он показывает ошибку. Как устранить эту ошибку
Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error: Line 24: </tr> Line 25: Line 26: @foreach (var item in @Model) Line 27: { Line 28: using (Html.BeginForm("Delete", "Employee", new { id = item.Id })) Source File: E:\Visual Studio 2019\Kuduvenkat MVC\BusinessLayer_Model2\BusinessLayer_Model2\Views\Employee\Index.cshtml Line: 26
Что я уже пробовал:
@model IEnumerable<BusinessLayer.Emp> @{ ViewBag.Title = "Index"; } <h2>Index</h2> <p> @Html.ActionLink("Create New", "Create") </p> <table class="table"> <tr> <th> @Html.DisplayNameFor(model => model.Name) </th> <th> @Html.DisplayNameFor(model => model.Gender) </th> <th> @Html.DisplayNameFor(model => model.Salary) </th> <th></th> </tr> @foreach (var item in @Model) { using (Html.BeginForm("Delete", "Employee", new { id = item.Id })) { <tr> <td> @Html.DisplayFor(modelItem => item.Name) </td> <td> @Html.DisplayFor(modelItem => item.Gender) </td> <td> @Html.DisplayFor(modelItem => item.Salary) </td> <td> @Html.ActionLink("Edit", "Edit", new { id = item.Id }) | <input type="submit" value="Delete" onclick="return confirm('Are you sure want to delete this record with Name = @item.Name')"/> </tr> } } </table>