FormExtensions.BeginForm Method
Writes an opening <form> tag to the response. When the user submits the form, the request will be processed by an action method.
Assembly: System.Web.Mvc (in System.Web.Mvc.dll)
| Name | Description | |
|---|---|---|
![]() ![]() | BeginForm(HtmlHelper) | Writes an opening <form> tag to the response. The form uses the POST method, and the request is processed by the action method for the view. |
![]() ![]() | BeginForm(HtmlHelper, Object) | Writes an opening <form> tag to the response and includes the route values in the action attribute. The form uses the POST method, and the request is processed by the action method for the view. |
![]() ![]() | BeginForm(HtmlHelper, RouteValueDictionary) | Writes an opening <form> tag to the response and includes the route values from the route value dictionary in the action attribute. The form uses the POST method, and the request is processed by the action method for the view. |
![]() ![]() | BeginForm(HtmlHelper, String, String) | Writes an opening <form> tag to the response and sets the action tag to the specified controller and action. The form uses the POST method. |
![]() ![]() | BeginForm(HtmlHelper, String, String, FormMethod) | Writes an opening <form> tag to the response and sets the action tag to the specified controller and action. The form uses the specified HTTP method. |
![]() ![]() | BeginForm(HtmlHelper, String, String, FormMethod, IDictionary<String, Object>) | Writes an opening <form> tag to the response and sets the action tag to the specified controller and action. The form uses the specified HTTP method and includes the HTML attributes from a dictionary. |
![]() ![]() | BeginForm(HtmlHelper, String, String, FormMethod, Object) | Writes an opening <form> tag to the response and sets the action tag to the specified controller and action. The form uses the specified HTTP method and includes the HTML attributes. |
![]() ![]() | BeginForm(HtmlHelper, String, String, Object) | Writes an opening <form> tag to the response, and sets the action tag to the specified controller, action, and route values. The form uses the POST method. |
![]() ![]() | BeginForm(HtmlHelper, String, String, Object, FormMethod) | Writes an opening <form> tag to the response and sets the action tag to the specified controller, action, and route values. The form uses the specified HTTP method. |
![]() ![]() | BeginForm(HtmlHelper, String, String, Object, FormMethod, Object) | Writes an opening <form> tag to the response and sets the action tag to the specified controller, action, and route values. The form uses the specified HTTP method and includes the HTML attributes. |
![]() ![]() | BeginForm(HtmlHelper, String, String, RouteValueDictionary) | Writes an opening <form> tag to the response, and sets the action tag to the specified controller, action, and route values from the route value dictionary. The form uses the POST method. |
![]() ![]() | BeginForm(HtmlHelper, String, String, RouteValueDictionary, FormMethod) | Writes an opening <form> tag to the response, and sets the action tag to the specified controller, action, and route values from the route value dictionary. The form uses the specified HTTP method. |
![]() ![]() | BeginForm(HtmlHelper, String, String, RouteValueDictionary, FormMethod, IDictionary<String, Object>) | Writes an opening <form> tag to the response, and sets the action tag to the specified controller, action, and route values from the route value dictionary. The form uses the specified HTTP method, and includes the HTML attributes from the dictionary. |
The BeginForm method renders a form that will be handled by a controller action method.
You can use this method in a using statement. In that case, the method renders the closing </form> tag at the end of the using block.
FormExtensions.BeginForm Method (HtmlHelper)
Writes an opening <form> tag to the response. The form uses the POST method, and the request is processed by the action method for the view.
Parameters
- htmlHelper
-
Type:
System.Web.Mvc.HtmlHelper
The HTML helper instance that this method extends.
The BeginForm method renders a form that will be handled by a controller action method.
You can use this method in a using block. In that case, the method renders the closing </form> tag at the end of the using block.
The following example shows how to use this form of the method.
@using (Html.BeginForm()) { @Html.TextBox("Name"); @Html.Password("Password"); <input type="submit" value="Sign In"> } // Produces the following form element // <form action="/Original Controller/Original Action" action="post">
FormExtensions.BeginForm Method (HtmlHelper, Object)
Writes an opening <form> tag to the response and includes the route values in the action attribute. The form uses the POST method, and the request is processed by the action method for the view.
Parameters
- htmlHelper
-
Type:
System.Web.Mvc.HtmlHelper
The HTML helper instance that this method extends.
- routeValues
-
Type:
System.Object
An object that contains the parameters for a route. The parameters are retrieved through reflection by examining the properties of the object. This object is typically created by using object initializer syntax.
The BeginForm method renders a form that will be handled by a controller action method.
You can use this method in a using block. In that case, the method renders the closing </form> tag at the end of the using block.
The following example shows how to use this form of the method.
@using (Html.BeginForm(new { UserId = "5" })) { @Html.TextBox("Name"); @Html.Password("Password"); <input type="submit" value="Sign In"> } // Produces the following form element // <form action="/Original Controller/Original Action?UserId=5" action="post">
FormExtensions.BeginForm Method (HtmlHelper, RouteValueDictionary)
Writes an opening <form> tag to the response and includes the route values from the route value dictionary in the action attribute. The form uses the POST method, and the request is processed by the action method for the view.
public static MvcForm BeginForm( this HtmlHelper htmlHelper, RouteValueDictionary routeValues )
Parameters
- htmlHelper
-
Type:
System.Web.Mvc.HtmlHelper
The HTML helper instance that this method extends.
- routeValues
-
Type:
System.Web.Routing.RouteValueDictionary
An object that contains the parameters for a route.
The BeginForm method renders a form that will be handled by a controller action method.
You can use this method in a using block. In that case, the method renders the closing </form> tag at the end of the using block.
The following example shows how to use this form of the method.
@{
var routeValues = new RouteValueDictionary();
routeValues.Add("UserId", "5");
}
@using (Html.BeginForm(routeValues))
{
@Html.TextBox("Name");
@Html.Password("Password");
<input type="submit" value="Sign In">
}
// Produces the following form element
// <form action="/Original Controller/Original Action?UserId=5" action="post">
FormExtensions.BeginForm Method (HtmlHelper, String, String)
Writes an opening <form> tag to the response and sets the action tag to the specified controller and action. The form uses the POST method.
public static MvcForm BeginForm( this HtmlHelper htmlHelper, string actionName, string controllerName )
Parameters
- htmlHelper
-
Type:
System.Web.Mvc.HtmlHelper
The HTML helper instance that this method extends.
- actionName
-
Type:
System.String
The name of the action method.
- controllerName
-
Type:
System.String
The name of the controller.
The BeginForm method renders a form that will be handled by a controller action method.
You can use this method in a using block. In that case, the method renders the closing </form> tag at the end of the using block.
The following example shows how to use this form of the method.
@using (Html.BeginForm("Login", "Account")) { @Html.TextBox("Name"); @Html.Password("Password"); <input type="submit" value="Sign In"> } // Produces the following form element // <form action="/Account/Login" action="post">
FormExtensions.BeginForm Method (HtmlHelper, String, String, FormMethod)
Writes an opening <form> tag to the response and sets the action tag to the specified controller and action. The form uses the specified HTTP method.
public static MvcForm BeginForm( this HtmlHelper htmlHelper, string actionName, string controllerName, FormMethod method )
Parameters
- htmlHelper
-
Type:
System.Web.Mvc.HtmlHelper
The HTML helper instance that this method extends.
- actionName
-
Type:
System.String
The name of the action method.
- controllerName
-
Type:
System.String
The name of the controller.
- method
-
Type:
System.Web.Mvc.FormMethod
The HTTP method for processing the form, either GET or POST.
The BeginForm method renders a form that will be handled by a controller action method.
You can use this method in a using block. In that case, the method renders the closing </form> tag at the end of the using block.
The following example shows how to use this form of the method.
@using (Html.BeginForm("Login", "Account", FormMethod.Post)) { @Html.TextBox("Name"); @Html.Password("Password"); <input type="submit" value="Sign In"> } // Produces the following form element // <form action="/Account/Login" action="post">
FormExtensions.BeginForm Method (HtmlHelper, String, String, FormMethod, IDictionary<String, Object>)
Writes an opening <form> tag to the response and sets the action tag to the specified controller and action. The form uses the specified HTTP method and includes the HTML attributes from a dictionary.
public static MvcForm BeginForm( this HtmlHelper htmlHelper, string actionName, string controllerName, FormMethod method, IDictionary<string, object> htmlAttributes )
Parameters
- htmlHelper
-
Type:
System.Web.Mvc.HtmlHelper
The HTML helper instance that this method extends.
- actionName
-
Type:
System.String
The name of the action method.
- controllerName
-
Type:
System.String
The name of the controller.
- method
-
Type:
System.Web.Mvc.FormMethod
The HTTP method for processing the form, either GET or POST.
- htmlAttributes
-
Type:
System.Collections.Generic.IDictionary<String, Object>
An object that contains the HTML attributes to set for the element.
The BeginForm method renders a form that will be handled by a controller action method.
You can use this method in a using block. In that case, the method renders the closing </form> tag at the end of the using block.
The following example shows how to use this form of the method.
@{
var attributes = new Dictionary<string, object>();
attributes.Add("Id", "Form1");
}
@using (Html.BeginForm("Login", "Account", FormMethod.Post, attributes))
{
@Html.TextBox("Name");
@Html.Password("Password");
<input type="submit" value="Sign In">
}
// Produces the following form element
// <form Id="Form1" action="/Account/Login" action="post">
FormExtensions.BeginForm Method (HtmlHelper, String, String, FormMethod, Object)
Writes an opening <form> tag to the response and sets the action tag to the specified controller and action. The form uses the specified HTTP method and includes the HTML attributes.
public static MvcForm BeginForm( this HtmlHelper htmlHelper, string actionName, string controllerName, FormMethod method, object htmlAttributes )
Parameters
- htmlHelper
-
Type:
System.Web.Mvc.HtmlHelper
The HTML helper instance that this method extends.
- actionName
-
Type:
System.String
The name of the action method.
- controllerName
-
Type:
System.String
The name of the controller.
- method
-
Type:
System.Web.Mvc.FormMethod
The HTTP method for processing the form, either GET or POST.
- htmlAttributes
-
Type:
System.Object
An object that contains the HTML attributes to set for the element.
The BeginForm method renders a form that will be handled by a controller action method.
You can use this method in a using block. In that case, the method renders the closing </form> tag at the end of the using block.
The htmlAttributes parameter consists of an object that contains name/value pairs. The attributes that are specified in the name/value pairs depend on the HTML element that is being rendered. For example, for a form element, you might provide the following anonymous object:
new { id = “text1”, accept-charset=”iso-8859-1” }
New With { .id = “text1”, .accept-charset=”iso-8859-1” }
The following example shows how to use this form of the method.
@using (Html.BeginForm("Login", "Account", FormMethod.Post, new { Id = "Form1" })) { @Html.TextBox("Name"); @Html.Password("Password"); <input type="submit" value="Sign In"> } // Produces the following form element // <form Id="Form1" action="/Account/Login" action="post">
FormExtensions.BeginForm Method (HtmlHelper, String, String, Object)
Writes an opening <form> tag to the response, and sets the action tag to the specified controller, action, and route values. The form uses the POST method.
public static MvcForm BeginForm( this HtmlHelper htmlHelper, string actionName, string controllerName, object routeValues )
Parameters
- htmlHelper
-
Type:
System.Web.Mvc.HtmlHelper
The HTML helper instance that this method extends.
- actionName
-
Type:
System.String
The name of the action method.
- controllerName
-
Type:
System.String
The name of the controller.
- routeValues
-
Type:
System.Object
An object that contains the parameters for a route. The parameters are retrieved through reflection by examining the properties of the object. This object is typically created by using object initializer syntax.
The BeginForm method renders a form that will be handled by a controller action method.
You can use this method in a using block. In that case, the method renders the closing </form> tag at the end of the using block.
The following example shows how to use this form of the method.
@using (Html.BeginForm("Login", "Account", new { UserId = "5" })) { @Html.TextBox("Name"); @Html.Password("Password"); <input type="submit" value="Sign In"> } // Produces the following form element // <form action="/Account/Login?UserId=5" action="post">
FormExtensions.BeginForm Method (HtmlHelper, String, String, Object, FormMethod)
Writes an opening <form> tag to the response and sets the action tag to the specified controller, action, and route values. The form uses the specified HTTP method.
public static MvcForm BeginForm( this HtmlHelper htmlHelper, string actionName, string controllerName, object routeValues, FormMethod method )
Parameters
- htmlHelper
-
Type:
System.Web.Mvc.HtmlHelper
The HTML helper instance that this method extends.
- actionName
-
Type:
System.String
The name of the action method.
- controllerName
-
Type:
System.String
The name of the controller.
- routeValues
-
Type:
System.Object
An object that contains the parameters for a route. The parameters are retrieved through reflection by examining the properties of the object. This object is typically created by using object initializer syntax.
- method
-
Type:
System.Web.Mvc.FormMethod
The HTTP method for processing the form, either GET or POST.
The BeginForm method renders a form that will be handled by a controller action method.
You can use this method in a using block. In that case, the method renders the closing </form> tag at the end of the using block.
The following example shows how to use this form of the method.
@using (Html.BeginForm("Login", "Account", new { UserId = "5" }, FormMethod.Post)) { @Html.TextBox("Name"); @Html.Password("Password"); <input type="submit" value="Sign In"> } // Produces the following form element // <form action="/Account/Login?UserId=5" action="post">
FormExtensions.BeginForm Method (HtmlHelper, String, String, Object, FormMethod, Object)
Writes an opening <form> tag to the response and sets the action tag to the specified controller, action, and route values. The form uses the specified HTTP method and includes the HTML attributes.
public static MvcForm BeginForm( this HtmlHelper htmlHelper, string actionName, string controllerName, object routeValues, FormMethod method, object htmlAttributes )
Parameters
- htmlHelper
-
Type:
System.Web.Mvc.HtmlHelper
The HTML helper instance that this method extends.
- actionName
-
Type:
System.String
The name of the action method.
- controllerName
-
Type:
System.String
The name of the controller.
- routeValues
-
Type:
System.Object
An object that contains the parameters for a route. The parameters are retrieved through reflection by examining the properties of the object. This object is typically created by using object initializer syntax.
- method
-
Type:
System.Web.Mvc.FormMethod
The HTTP method for processing the form, either GET or POST.
- htmlAttributes
-
Type:
System.Object
An object that contains the HTML attributes to set for the element.
The BeginForm method renders a form that will be handled by a controller action method.
You can use this method in a using block. In that case, the method renders the closing </form> tag at the end of the using block.
The htmlAttributes parameter consists of an object that contains name/value pairs. The attributes that are specified in the name/value pairs depend on the HTML element that is being rendered. For example, for a form element, you might provide the following anonymous object:
The following example shows how to use this form of the method.
@using (Html.BeginForm("Login", "Account", new { UserId = "5" }, FormMethod.Post, new { Id = "Form1" })) { @Html.TextBox("Name"); @Html.Password("Password"); <input type="submit" value="Sign In"> } // Produces the following form element // <form Id="Form1" action="/Account/Login?UserId=5" action="post">
FormExtensions.BeginForm Method (HtmlHelper, String, String, RouteValueDictionary)
Writes an opening <form> tag to the response, and sets the action tag to the specified controller, action, and route values from the route value dictionary. The form uses the POST method.
public static MvcForm BeginForm( this HtmlHelper htmlHelper, string actionName, string controllerName, RouteValueDictionary routeValues )
Parameters
- htmlHelper
-
Type:
System.Web.Mvc.HtmlHelper
The HTML helper instance that this method extends.
- actionName
-
Type:
System.String
The name of the action method.
- controllerName
-
Type:
System.String
The name of the controller.
- routeValues
-
Type:
System.Web.Routing.RouteValueDictionary
An object that contains the parameters for a route.
The BeginForm method renders a form that will be handled by a controller action method.
You can use this method in a using block. In that case, the method renders the closing </form> tag at the end of the using block.
The following example shows how to use this form of the method.
@{
var routeValues = new RouteValueDictionary();
routeValues.Add("UserId", "5");
}
@using (Html.BeginForm("Login", "Account", routeValues))
{
@Html.TextBox("Name");
@Html.Password("Password");
<input type="submit" value="Sign In">
}
// Produces the following form element
// <form action="/Account/Login?UserId=5" action="post">
FormExtensions.BeginForm Method (HtmlHelper, String, String, RouteValueDictionary, FormMethod)
Writes an opening <form> tag to the response, and sets the action tag to the specified controller, action, and route values from the route value dictionary. The form uses the specified HTTP method.
public static MvcForm BeginForm( this HtmlHelper htmlHelper, string actionName, string controllerName, RouteValueDictionary routeValues, FormMethod method )
Parameters
- htmlHelper
-
Type:
System.Web.Mvc.HtmlHelper
The HTML helper instance that this method extends.
- actionName
-
Type:
System.String
The name of the action method.
- controllerName
-
Type:
System.String
The name of the controller.
- routeValues
-
Type:
System.Web.Routing.RouteValueDictionary
An object that contains the parameters for a route.
- method
-
Type:
System.Web.Mvc.FormMethod
The HTTP method for processing the form, either GET or POST.
The BeginForm method renders a form that will be handled by a controller action method.
You can use this method in a using block. In that case, the method renders the closing </form> tag at the end of the using block.
The following example shows how to use this form of the method.
@{
var routeValues = new RouteValueDictionary();
routeValues.Add("UserId", "5");
}
@using (Html.BeginForm("Login", "Account", routeValues, FormMethod.Post))
{
@Html.TextBox("Name");
@Html.Password("Password");
<input type="submit" value="Sign In">
}
// Produces the following form element
// <form action="/Account/Login?UserId=5" action="post">
FormExtensions.BeginForm Method (HtmlHelper, String, String, RouteValueDictionary, FormMethod, IDictionary<String, Object>)
Writes an opening <form> tag to the response, and sets the action tag to the specified controller, action, and route values from the route value dictionary. The form uses the specified HTTP method, and includes the HTML attributes from the dictionary.
public static MvcForm BeginForm( this HtmlHelper htmlHelper, string actionName, string controllerName, RouteValueDictionary routeValues, FormMethod method, IDictionary<string, object> htmlAttributes )
Parameters
- htmlHelper
-
Type:
System.Web.Mvc.HtmlHelper
The HTML helper instance that this method extends.
- actionName
-
Type:
System.String
The name of the action method.
- controllerName
-
Type:
System.String
The name of the controller.
- routeValues
-
Type:
System.Web.Routing.RouteValueDictionary
An object that contains the parameters for a route.
- method
-
Type:
System.Web.Mvc.FormMethod
The HTTP method for processing the form, either GET or POST.
- htmlAttributes
-
Type:
System.Collections.Generic.IDictionary<String, Object>
An object that contains the HTML attributes to set for the element.
The BeginForm method renders a form that will be handled by a controller action method.
You can use this method in a using block. In that case, the method renders the closing </form> tag at the end of the using block.
The following example shows how to use this form of the method.
@{
var routeValues = new RouteValueDictionary();
routeValues.Add("UserId", "5");
var attributes = new Dictionary<string, object>();
attributes.Add("Id", "Form1");
}
@using (Html.BeginForm("Login", "Account", routeValues, FormMethod.Post, attributes))
{
@Html.TextBox("Name");
@Html.Password("Password");
<input type="submit" value="Sign In">
}
// Produces the following form element
// <form Id="Form1" action="/Account/Login?UserId=5" action="post">

