How to pass in ID with Html.BeginForm()?

Viewed 76626

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

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

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

How do I pass in the ID?

4 Answers

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.

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

<!-- ACTION: Category/Update/Id | Method:Post-->
@using (Html.BeginForm("Update", "Category",new {Id = @Model.Id },FormMethod.Post)){}
Related