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?
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.
"BeginForm()" is an extension method that writes an opening "<form>" tag to the response. "BeginForm()" is an extension method for both HtmlHelper and AjaxHelper classes.
What is Html.BeginForm? What is Html.BeginForm? Html.BeginForm is the Html Helper Extension Method that is used for creating and rendering the form in HTML. This method makes your job easier in creating form. Here, is the method to create a form using Html.BeginForm extension method in ASP.NET MVC5.
The BeginForm () method is an extension method of the HtmlHelper class that writes an opening "<form>" tag and it also calls the "Dispose ()" method that writes a closing "</form>" tag.
Generally, 3 parameters are used when creating Html.BeginForm. ActionMethod – It defines which action method is look for when submit button is clicked. ControllerName – It defines, which controller keeps the defined action method.
"BeginForm ()" is an extension method that writes an opening "" tag to the response. "BeginForm ()" is an extension method for both HtmlHelper and AjaxHelper classes.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With