次のRazorビューが表示され、HDDのリストが表示されるので、ユーザーがカートに追加します。ユーザーがHDDの各行の横にあるボタンを押すと、数量とHDDのIDがコントローラーに渡されます。ただし、各HDDのIDは正しく表示されますが、コントローラーのパラメーターを調べると、「hddId」は常に1であり、「quantity」は正しく5です。
@model IEnumerable<TestStore.Models.Hdd>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
@using(Html.BeginForm("AddToCart","Cart")){
<table>
<tr>
<th>
Ident
</th>
<th>
Brand
</th>
<th>
Name
</th>
<th>
Model
</th>
<th>
Speed
</th>
<th>
Capacity
</th>
<th>
Cache
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.hddId)
</td>
<td>
@Html.Hidden("hddId", item.hddId)
@Html.Hidden("quantity", 5)
@Html.DisplayFor(modelItem => item.brand)
</td>
<td>
@Html.DisplayFor(modelItem => item.name)
</td>
<td>
@Html.DisplayFor(modelItem => item.model)
</td>
<td>
@Html.DisplayFor(modelItem => item.speed)
</td>
<td>
@Html.DisplayFor(modelItem => item.capacity)
</td>
<td>
@Html.DisplayFor(modelItem => item.cache)
</td>
<td>
<input type="submit" value="Add to Cart" />
</td>
</tr>
}
</table>
}