Controller:
public ActionResult Delete(int id)
{
Student _std = new Student();
var abc = _dbcon.StudentList.Where(c => c.Roll_ID.Equals(id)).SingleOrDefault();
_dbcon.StudentList.Remove(abc);
_dbcon.SaveChanges();
return View("Test");
}
This is my view and the error comes at foreach loop
View:
@foreach (StudentViewModel _EachStd in @Model.StudentList)
{
<tr>
<td> @_EachStd.Roll_ID</td>
<td> @_EachStd.Name</td>
<td> @_EachStd.Maths</td>
<td> @_EachStd.Urdu</td>
<td> @_EachStd.English</td>
<td>@_EachStd.ObtainNumber</td>
<td>@_EachStd.Percentage</td>
<td> @_EachStd.Grade</td>
<td>@Html.ActionLink("Edit", "Edit", "Home", new {id= @_EachStd.Roll_ID },null)</td>
<td>@Html.ActionLink("Delete", "Delete", "Home", new { id = @_EachStd.Roll_ID }, null)</td>
</tr>
}
</tbody>
</table>
I got Null Error exception, but after refresh i got the record delete. But why the error occur I dont get It.Whenever i run this code my Edit controller is working correctly but my Delete controller is not working correctly, and error is occur like there is "Null erroe exception"