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?
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?
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, 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.