Say I have a view like this:
@model Models.CustomerModel
@{
ViewBag.Title = "Details";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Details</h2>
<div>
@*<h4>ApplicationModel</h4>*@
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.FirstName)
</dt>
<dd>
@Html.DisplayFor(model => model.FirstName)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Surname)
</dt>
<dd>
@Html.DisplayFor(model => model.Surname)
</dd>
</dl>
</div>
Say CustomerModel also has a collection of Orders. The Order class looks like this:
public class Order {
public int OrderID {get; set; }
public datetime OrderDate {get; set; }
How can I put all the Orders liked to the Customer on the same view? I have tried this (under the code above):
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.OrderID)
</th>
<th>
@Html.DisplayNameFor(model => model.OrderDate)
</th>
</tr>
@foreach (var item in model.Orders)
{
<tr>
<td>
@Html.DisplayFor(item => item.OrderID)
</td>
<td>
@Html.DisplayFor(item => item.Description)
</td>
</tr>
}
The error I get is:
The parameters dictionary contains a null entry for parameter 'orderid' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Delete(Int32)'.
If I remove the second fragment of code (for each loop), then it works properly. How do I add the second fragment of code?