I only want to add the formId in the beginForm()
If i try using
Html.BeginForm(null, null, FormMethod.Post, new {@id="Id"})
then the Html generated is
<form action="/newquestion/payment/b9f88f80-f31f-4144-9066-55384c9f1cfc" ... >
i don't know how that action url is generated so i tried,
Html.BeginForm(new {@id="Id"})
but then the action url looks like this
<form action="/newquestion/payment/Id... >
In both the cases the action url is not what it should be and it is not hitting the post action of the controller.
Because of in System.Web.Mvc.Html ( in System.Web.Mvc.dll ) the begin form is defined like bellowed:-
So, it worked for me in MVC 4
Change @id to id.
When you are trying to generate a route, such as with
BeginForm
, MVC will do its best to include things that you might need.If you're at
domain.com/Home/Index/b9f88f80-f31f-4144-9066-55384c9f1cfc
and you use the code that you have provided than the form will be generated with the action, controller and route values as it finds them.One way to get around this is to force id to be nothing (such as an empty string).
Observe:
The
new { @id = string.Empty }
is an anonymous object that represents the route values.