tags:

views:

4236

answers:

3

In ASP.NET MVC I'm using the HTML helper

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

But I need to post to: /controller/action/23434

How do I pass in the ID?

+4  A: 

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

Matt Hinze
that doesn't work, it adds an attribute to the form tag.
mrblah
check the parameter name routeValues - make sure you are using that one not htmlAttributes.
Matt Hinze
+5  A: 

Matt's should work fine. If you are still passing in FormMethod.Post, though, you need to do it like this:

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

Reversing the third and fourth parameters will result in the Id being treated as an attribute instead of a route value.

Jon Freeland
A: 

Jon, are you saying that placing the new{@id="Id"} as the last parameter is the way to go or that inversing it from there? At any rate, I had to build my html.beginform this way for it to compile w/out errors:

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

if I placed the new{@id="Id"} before the Post method it would throw an error.

Neurothustra