I am working in an ASP.NET 3.5 MVC application where I have a view with several forms. Form 1 contains information about the products and forms a shopping card with a delete button. Form 2 is provided below and should be used to retrieve information from the shopping cart and create its order.
<% using (Html.BeginForm()) { %>
<%=Html.Hidden(Order.ProductId", "E63EF586-F625-4C8D-B82E-E63A6FA4A63C")%>
<%=Html.Hidden(Order.Amount", 16)%>
<input type="submit" value="Pay" />
The first form contains a similar initial form with a foreach loop to get product information from the model. When I use the submit button in the second form, everything seems to be sent, and the action in the controller for the first form tries to process the request. This is where the error occurs because the information in the viewmodel is not as expected.
The controller that is trying to process the request:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult ShowShoppingcartForm([Bind(Prefix = "Order")] MyViewmodel viewModel)
{
}
The controller that is expected to process the request:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult SaveOrder([Bind(Prefix = "Order")] MyViewmodel viewModel)
{
}
:
, , , , . , :
1:
<%foreach (var cartItem in Model.ProductList) { %>
<% using (Html.BeginForm("ShoppingCart","ControllerName", FormMethod.Post,null)) { %>
<tr>
<td> <%=Html.Hidden("Cart.ProductVariantId", cartItem.ProductVariant.Id)%>
<%=Html.Encode(cartItem.ProductVariant.Product.Name)%> </td>
<td> <%=Html.Encode(cartItem.ProductVariant.Product.Description)%> </td>
<td> <%=Html.TextBox("Cart.Amount", cartItem.Amount)%></td>
<td> <%=Html.Encode(cartItem.Amount)%> </td>
<td> <%=Html.Encode(cartItem.Product.PriceInCents)%> </td>
<td> <input type="submit" value="Remove" width="50px" /> </td>
<td> <input type="submit" value="Submit" width="50px" /> </td>
</tr>
<% } %>
<% } %>
2:
<% using (Html.BeginForm("SaveOrder", "ControllerName", FormMethod.Post, null))
{%>
<%=Html.Hidden("Order.ProductId", "E63EF586-F625-4C8D-B82E-E63A6FA4A63C"")%>
<%=Html.Hidden(Order.Amount", 1)%>
<input type="submit" value="Pay" />
<%} %>