Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

asp.net-mvc

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?

like image 339
mrblah Avatar asked May 18 '09 15:05

mrblah


People also ask

How do you pass ID in BeginForm?

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.

What is HTML BeginForm ()?

"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 in MVC?

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.

What is the beginform () method of htmlhelper?

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.

What are the parameters used when creating a form in HTML?

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.

What is the use of beginform () 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.


1 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.

like image 78
Jonathan Freeland Avatar answered Oct 04 '22 17:10

Jonathan Freeland