0

Whenever I run the program, I get this error:

Exception thrown
System.NullReferenceException: 'Object reference not set to an instance of an object.'

E_Shopping_System.Models.Customer.ShowallCustomer.get returned null.

@foreach (var item in Model.ShowallCustomer)

This is the code

@foreach (var item in Model.ShowallCustomer)
{
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Address)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Mobileno)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Birthdate)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.EmailID)
        </td>
        <td>
            @Html.ActionLink("Modify", "Edit", new { id = item.CustomerID }) |
            @Html.ActionLink("Detail", "Details", new { id = item.CustomerID }) |
            @*@Html.ActionLink("Remove", "Delete", new { id = item.CustomerID })*@
            @Html.ActionLink("Remove", "Delete", new { id = item.CustomerID },
            new { onclick = "return confirm('Are sure wants to delete?');" })
        </td>
    </tr>
}
Qing Guo
  • 6,041
  • 1
  • 2
  • 10
  • 2
    What is your Model.ShowallCustomer? Have you send the data of Model.ShowallCustomer from the controller to the view? Besides, have a look at [What is a NullReferenceException and how do I fix it](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it)? – Qing Guo Nov 15 '22 at 05:34
  • most likely u did not pass the model from your controller. Check Return View() . Where you pass the model correclty. e.g. return View(YoutModel); – Yat Fei Leong Nov 16 '22 at 12:59

0 Answers0