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?
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?
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})
Html.BeginForm("action", "controller", new { id = ViewBag.FileID },
FormMethod.Post, new { id = "feedbackform" })
As for the querystring, ?type=golden
, I don't know how to do that. Of course, a querysting is a get, and undermines the whole purpose of FormMethod.Post
. I mean, you could use FormMethod.Get
, if you want querystring data, and this might be what you are looking for.
Additionally, you can avoid html.beginform
and do the querystring, get + post, manually with a form tag.
Thirdly, if you are using the form, you can make a hidden field:
[input type=hidden name="type" value="golden"]
Then, when the submit button is pressed the value is passed properly as a form variable.
<!-- ACTION: Category/Update/Id | Method:Post-->
@using (Html.BeginForm("Update", "Category",new {Id = @Model.Id },FormMethod.Post)){}