MVC: Submit one form from a page with multiple forms
Posted
by Rob
on Stack Overflow
See other posts from Stack Overflow
or by Rob
Published on 2010-04-09T10:12:09Z
Indexed on
2010/04/09
10:23 UTC
Read the original article
Hit count: 298
I'm working in an ASP.NET 3.5 MVC application where i've got a view with multiple forms in it. Form 1 contains information about products and will form a shoppingcart with a remove button. Form 2 is as below and is to be used to get the information from the shoppingcart and create an order of it.
<% using (Html.BeginForm()) { %>
<%=Html.Hidden(Order.ProductId", "E63EF586-F625-4C8D-B82E-E63A6FA4A63C")%>
<%=Html.Hidden(Order.Amount", 1)%>
<input type="submit" value="Pay" />
<%} %>
The first form contains a similar beginform with a foreach loop to get the information about the products from the model. When i use the submit button on the second form everything seems to be submitted and the action in the controller for the first form is trying to handle the request. That is where the error occurce because the information in the viewmodel isn't corresponding to what is being expected.
The controller which is trying to handle the request:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult ShowShoppingcartForm([Bind(Prefix = "Order")] MyViewmodel viewModel)
{
//..
}
The controller which is expected to handle the request:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult SaveOrder([Bind(Prefix = "Order")] MyViewmodel viewModel)
{
throw new NotImplementedException();
}
© Stack Overflow or respective owner