I have a shopping cart where the following are true:
- There is one "Remove" button for each product in the shopping cart
- There is one editable quantity text box for each product in the shopping cart
- There is one "Update" button for the entire shopping cart
The idea is that the user can modify the quantities for each product in the cart and click "Update" to commit the changes.
How would you program the "Update" button using MVC? Would you wrap the entire shopping cart in a form that posts back to itself and somehow locate the quantity values in the FormCollection? The problem with that approach is that since the "Remove" buttons each live in their own forms I would now be doing nested forms on the page and I am not even sure that is allowed.
Any help would be appreciated.
Thanks
<% using (Html.BeginForm("Index", "Cart")) { %>
<table>
<tr>
<th> </th>
</tr>
<% foreach (var item in Model) { %>
<tr>
<td>
<input name="qty" type="text" value="<%=item.Quantity%>" maxlength="2" />
<% using (Html.BeginForm("RemoveOrderItem", "Cart")) { %>
<%= Html.Hidden("ShoppingCartItemID", item.ShoppingCartItemID) %>
<input name="add" type="submit" value="Remove" />
<%} %>
</td>
</tr>
<% } %>
</table>
<input name="update" type="submit" value="Update" />
<%} %>
How would I incorporate the bottom input into this form?