I have a view with an enumerable model. I'm trying to bind text boxes with the value of the instance of the object. Here is my view.
@model IEnumerable<SeniorProjectMVC.Models.Cart>
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h3>Your cart</h3>
@*<p>
@Html.ActionLink("Create New", "Create")
</p>*@
<div class="row">
<div class="large-2 columns">
<h4> @Html.DisplayNameFor(model => model.Quantity)</h4>
</div>
<div class="large-4 columns">
<h4>@Html.DisplayNameFor(model => model.Sku.Product.Name)</h4>
</div>
<div class="large-2 columns">
<h4>@Html.DisplayNameFor(model => model.Sku.Product.Price)</h4>
</div>
<div class="large-1 columns">
<h4>In stock</h4>
</div>
<div class="large-3 columns">
</div>
</div>
@foreach (var item in Model)
{
<div class="row">
<div class="large-2 columns">
@Html.TextBox(item.Quantity.ToString())
</div>
<div class="large-4 columns">
@Html.Display(item.Sku.Product.Name)
</div>
<div class="large-2 columns">
@(item.Sku.Product.Price.ToString("c"))
</div>
<div class="large-1 columns">
@(item.Sku.Quantity > 0 ? "In Stock" : "Out of stock")
</div>
<div class="large-3 columns">
@Html.ActionLink("Edit", "Edit", new { id = item.ID }, new { @class = "button primary" }) |
@Html.ActionLink("Details", "Details", new { id = item.ID }, new { @class = "button primary" }) |
@Html.ActionLink("Delete", "Delete", new { id = item.ID }, new { @class = "button primary" })
</div>
</div>
}
The issue I seem to have run into is that the quantity won't populate in the textbox and it seems like the name for the product also isn't showing up. I know the Product Names have values, but they aren't displaying. Also, if I wanted to post back this collection in case of a value changing, what's the correct way to post back all the textbox values with their corresponding ID's so I can update the quantities in the cart that have changed.