I am having challenges on how to do bulk update in ASP.NET MVC.
I have the following view which is bound to the vwOrderCart
model:
@model List<Kweb.Data.vwOrderCart>
@{
ViewBag.Title = "Create Order";
}
This is a table on the view that iterates through the model and display data on the view:
foreach (var item in Model)
{
<tr>
<td>
<input type="hidden" name="OrderCartId" value="@item.OrderCartId" />
@item.ProductName
</td>
<td><input class="form-control" name='"OrderList["+ @item.OrderCartId +"].OrderPrice"' value="@string.Format("{0:C}", item.OrderPrice).Trim('$')" />
</td>
<td><input class="form-control" name='"OrderList["+ @item.OrderCartId +"].Qty"' value="@item.Qty" /></td>
<td><input class="form-control" name='"OrderList["+ @item.OrderCartId +"].Discount"' value="@string.Format("{0:C}", item.Discount).Trim('$')" /></td>
<td>@string.Format("{0:C}", item.TaxValue).Trim('$')</td>
<td>@string.Format("{0:C}", item.TotalPrice).Trim('$')</td>
<td><a href="#" onclick="deleteCart(@item.OrderCartId)" class="btn btn-sm default red-stripe"><i class="fa fa-times-circle"></i></a></td>
</tr>
}
And the following is my ActionResultController
[HttpPost]
public ActionResult Index(List<vwOrderCart> OrderList)
{
}
But the OrderList
show null
when I debug.
How do I send my controls on the form to the controller?