How to pass id using Html.BeginForm ()?

In ASP.NET MVC I use HTML Helper

Html.BeginForm("ActionName", "Controller", FormMethod.Post); 

But I need to send a message: / controller / action / 23434

How to pass an identifier?

+39
asp.net-mvc
May 18, '09 at 15:33
source share
3 answers

Matt should work fine. If you still pass in FormMethod.Post , you should do it like this:

 Html.BeginForm("action","controller", new { Id = 12345 }, FormMethod.Post); 

Reversing the third and fourth parameters will cause Id be considered as an attribute instead of a route value.

+62
May 18 '09 at 15:49
source share

Html.BeginForm("action", "controller", new {Id = 12345})

+10
May 18, '09 at 15:35
source share
 Html.BeginForm("action", "controller", new { id = ViewBag.FileID }, FormMethod.Post, new { id = "feedbackform" }) 

Regarding the request ?type=golden , I don't know how to do this. Of course, querysting is getting and undermining the whole purpose of FormMethod.Post . I mean, you can use FormMethod.Get if you want to receive data with requests, and this may be what you are looking for.

Alternatively, you can avoid html.beginform and do a querystring, get a + message, manually with a form tag.

Thirdly, if you use a form, you can create a hidden field:

 [input type=hidden name="type" value="golden"] 

Then, when the submit button is pressed, the value is passed correctly as a form variable.

+7
09 Oct '13 at 18:39
source share



All Articles