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.

Namespace:   System.Web.Mvc.Html
Assembly:  System.Web.Mvc (in System.Web.Mvc.dll)

Overload List

Name Description
System_CAPS_pubmethodSystem_CAPS_static 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.

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

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

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

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

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

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

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

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

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

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

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

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

Remarks

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.

See Also

FormExtensions Class
System.Web.Mvc.Html Namespace

Return to top

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.

Syntax

public static MvcForm BeginForm(
    this HtmlHelper htmlHelper
)
public:
[ExtensionAttribute]
static MvcForm^ BeginForm(
    HtmlHelper^ htmlHelper
)
static member BeginForm : 
        htmlHelper:HtmlHelper -> MvcForm
<ExtensionAttribute>
Public Shared Function BeginForm (
    htmlHelper As HtmlHelper
) As MvcForm

Parameters

Return Value

Type: System.Web.Mvc.Html.MvcForm

An opening <form> tag.

Remarks

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.

Examples

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">

Return to top

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.

Syntax

public static MvcForm BeginForm(
    this HtmlHelper htmlHelper,
    object routeValues
)
public:
[ExtensionAttribute]
static MvcForm^ BeginForm(
    HtmlHelper^ htmlHelper,
    Object^ routeValues
)
static member BeginForm : 
        htmlHelper:HtmlHelper *
        routeValues:Object -> MvcForm
<ExtensionAttribute>
Public Shared Function BeginForm (
    htmlHelper As HtmlHelper,
    routeValues As Object
) As MvcForm

Parameters

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

Return Value

Type: System.Web.Mvc.Html.MvcForm

An opening <form> tag.

Remarks

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.

Examples

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">

Return to top

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.

Syntax

public static MvcForm BeginForm(
    this HtmlHelper htmlHelper,
    RouteValueDictionary routeValues
)
public:
[ExtensionAttribute]
static MvcForm^ BeginForm(
    HtmlHelper^ htmlHelper,
    RouteValueDictionary^ routeValues
)
static member BeginForm : 
        htmlHelper:HtmlHelper *
        routeValues:RouteValueDictionary -> MvcForm
<ExtensionAttribute>
Public Shared Function BeginForm (
    htmlHelper As HtmlHelper,
    routeValues As RouteValueDictionary
) As MvcForm

Parameters

Return Value

Type: System.Web.Mvc.Html.MvcForm

An opening <form> tag.

Remarks

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.

Examples

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">

Return to top

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.

Syntax

public static MvcForm BeginForm(
    this HtmlHelper htmlHelper,
    string actionName,
    string controllerName
)
public:
[ExtensionAttribute]
static MvcForm^ BeginForm(
    HtmlHelper^ htmlHelper,
    String^ actionName,
    String^ controllerName
)
static member BeginForm : 
        htmlHelper:HtmlHelper *
        actionName:string *
        controllerName:string -> MvcForm
<ExtensionAttribute>
Public Shared Function BeginForm (
    htmlHelper As HtmlHelper,
    actionName As String,
    controllerName As String
) As MvcForm

Parameters

Return Value

Type: System.Web.Mvc.Html.MvcForm

An opening <form> tag.

Remarks

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.

Examples

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">

Return to top

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.

Syntax

public static MvcForm BeginForm(
    this HtmlHelper htmlHelper,
    string actionName,
    string controllerName,
    FormMethod method
)
public:
[ExtensionAttribute]
static MvcForm^ BeginForm(
    HtmlHelper^ htmlHelper,
    String^ actionName,
    String^ controllerName,
    FormMethod method
)
static member BeginForm : 
        htmlHelper:HtmlHelper *
        actionName:string *
        controllerName:string *
        method:FormMethod -> MvcForm
<ExtensionAttribute>
Public Shared Function BeginForm (
    htmlHelper As HtmlHelper,
    actionName As String,
    controllerName As String,
    method As FormMethod
) As MvcForm

Parameters

Return Value

Type: System.Web.Mvc.Html.MvcForm

An opening <form> tag.

Remarks

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.

Examples

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">

Return to top

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.

Syntax

public static MvcForm BeginForm(
    this HtmlHelper htmlHelper,
    string actionName,
    string controllerName,
    FormMethod method,
    IDictionary<string, object> htmlAttributes
)
public:
[ExtensionAttribute]
static MvcForm^ BeginForm(
    HtmlHelper^ htmlHelper,
    String^ actionName,
    String^ controllerName,
    FormMethod method,
    IDictionary<String^, Object^>^ htmlAttributes
)
static member BeginForm : 
        htmlHelper:HtmlHelper *
        actionName:string *
        controllerName:string *
        method:FormMethod *
        htmlAttributes:IDictionary<string, Object> -> MvcForm
<ExtensionAttribute>
Public Shared Function BeginForm (
    htmlHelper As HtmlHelper,
    actionName As String,
    controllerName As String,
    method As FormMethod,
    htmlAttributes As IDictionary(Of String, Object)
) As MvcForm

Parameters

Return Value

Type: System.Web.Mvc.Html.MvcForm

An opening <form> tag.

Remarks

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.

Examples

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">

Return to top

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.

Syntax

public static MvcForm BeginForm(
    this HtmlHelper htmlHelper,
    string actionName,
    string controllerName,
    FormMethod method,
    object htmlAttributes
)
public:
[ExtensionAttribute]
static MvcForm^ BeginForm(
    HtmlHelper^ htmlHelper,
    String^ actionName,
    String^ controllerName,
    FormMethod method,
    Object^ htmlAttributes
)
static member BeginForm : 
        htmlHelper:HtmlHelper *
        actionName:string *
        controllerName:string *
        method:FormMethod *
        htmlAttributes:Object -> MvcForm
<ExtensionAttribute>
Public Shared Function BeginForm (
    htmlHelper As HtmlHelper,
    actionName As String,
    controllerName As String,
    method As FormMethod,
    htmlAttributes As Object
) As MvcForm

Parameters

  • htmlAttributes
    Type: System.Object

    An object that contains the HTML attributes to set for the element.

Return Value

Type: System.Web.Mvc.Html.MvcForm

An opening <form> tag.

Remarks

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” }

Examples

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">

Return to top

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.

Syntax

public static MvcForm BeginForm(
    this HtmlHelper htmlHelper,
    string actionName,
    string controllerName,
    object routeValues
)
public:
[ExtensionAttribute]
static MvcForm^ BeginForm(
    HtmlHelper^ htmlHelper,
    String^ actionName,
    String^ controllerName,
    Object^ routeValues
)
static member BeginForm : 
        htmlHelper:HtmlHelper *
        actionName:string *
        controllerName:string *
        routeValues:Object -> MvcForm
<ExtensionAttribute>
Public Shared Function BeginForm (
    htmlHelper As HtmlHelper,
    actionName As String,
    controllerName As String,
    routeValues As Object
) As MvcForm

Parameters

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

Return Value

Type: System.Web.Mvc.Html.MvcForm

An opening <form> tag.

Remarks

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.

Examples

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">

Return to top

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.

Syntax

public static MvcForm BeginForm(
    this HtmlHelper htmlHelper,
    string actionName,
    string controllerName,
    object routeValues,
    FormMethod method
)
public:
[ExtensionAttribute]
static MvcForm^ BeginForm(
    HtmlHelper^ htmlHelper,
    String^ actionName,
    String^ controllerName,
    Object^ routeValues,
    FormMethod method
)
static member BeginForm : 
        htmlHelper:HtmlHelper *
        actionName:string *
        controllerName:string *
        routeValues:Object *
        method:FormMethod -> MvcForm
<ExtensionAttribute>
Public Shared Function BeginForm (
    htmlHelper As HtmlHelper,
    actionName As String,
    controllerName As String,
    routeValues As Object,
    method As FormMethod
) As MvcForm

Parameters

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

Return Value

Type: System.Web.Mvc.Html.MvcForm

An opening <form> tag.

Remarks

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.

Examples

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">

Return to top

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.

Syntax

public static MvcForm BeginForm(
    this HtmlHelper htmlHelper,
    string actionName,
    string controllerName,
    object routeValues,
    FormMethod method,
    object htmlAttributes
)
public:
[ExtensionAttribute]
static MvcForm^ BeginForm(
    HtmlHelper^ htmlHelper,
    String^ actionName,
    String^ controllerName,
    Object^ routeValues,
    FormMethod method,
    Object^ htmlAttributes
)
static member BeginForm : 
        htmlHelper:HtmlHelper *
        actionName:string *
        controllerName:string *
        routeValues:Object *
        method:FormMethod *
        htmlAttributes:Object -> MvcForm
<ExtensionAttribute>
Public Shared Function BeginForm (
    htmlHelper As HtmlHelper,
    actionName As String,
    controllerName As String,
    routeValues As Object,
    method As FormMethod,
    htmlAttributes As Object
) As MvcForm

Parameters

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

  • htmlAttributes
    Type: System.Object

    An object that contains the HTML attributes to set for the element.

Return Value

Type: System.Web.Mvc.Html.MvcForm

An opening <form> tag.

Remarks

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” }

Examples

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">

Return to top

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.

Syntax

public static MvcForm BeginForm(
    this HtmlHelper htmlHelper,
    string actionName,
    string controllerName,
    RouteValueDictionary routeValues
)
public:
[ExtensionAttribute]
static MvcForm^ BeginForm(
    HtmlHelper^ htmlHelper,
    String^ actionName,
    String^ controllerName,
    RouteValueDictionary^ routeValues
)
static member BeginForm : 
        htmlHelper:HtmlHelper *
        actionName:string *
        controllerName:string *
        routeValues:RouteValueDictionary -> MvcForm
<ExtensionAttribute>
Public Shared Function BeginForm (
    htmlHelper As HtmlHelper,
    actionName As String,
    controllerName As String,
    routeValues As RouteValueDictionary
) As MvcForm

Parameters

Return Value

Type: System.Web.Mvc.Html.MvcForm

An opening <form> tag.

Remarks

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.

Examples

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">

Return to top

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.

Syntax

public static MvcForm BeginForm(
    this HtmlHelper htmlHelper,
    string actionName,
    string controllerName,
    RouteValueDictionary routeValues,
    FormMethod method
)
public:
[ExtensionAttribute]
static MvcForm^ BeginForm(
    HtmlHelper^ htmlHelper,
    String^ actionName,
    String^ controllerName,
    RouteValueDictionary^ routeValues,
    FormMethod method
)
static member BeginForm : 
        htmlHelper:HtmlHelper *
        actionName:string *
        controllerName:string *
        routeValues:RouteValueDictionary *
        method:FormMethod -> MvcForm
<ExtensionAttribute>
Public Shared Function BeginForm (
    htmlHelper As HtmlHelper,
    actionName As String,
    controllerName As String,
    routeValues As RouteValueDictionary,
    method As FormMethod
) As MvcForm

Parameters

Return Value

Type: System.Web.Mvc.Html.MvcForm

An opening <form> tag.

Remarks

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.

Examples

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">

Return to top

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.

Syntax

public static MvcForm BeginForm(
    this HtmlHelper htmlHelper,
    string actionName,
    string controllerName,
    RouteValueDictionary routeValues,
    FormMethod method,
    IDictionary<string, object> htmlAttributes
)
public:
[ExtensionAttribute]
static MvcForm^ BeginForm(
    HtmlHelper^ htmlHelper,
    String^ actionName,
    String^ controllerName,
    RouteValueDictionary^ routeValues,
    FormMethod method,
    IDictionary<String^, Object^>^ htmlAttributes
)
static member BeginForm : 
        htmlHelper:HtmlHelper *
        actionName:string *
        controllerName:string *
        routeValues:RouteValueDictionary *
        method:FormMethod *
        htmlAttributes:IDictionary<string, Object> -> MvcForm
<ExtensionAttribute>
Public Shared Function BeginForm (
    htmlHelper As HtmlHelper,
    actionName As String,
    controllerName As String,
    routeValues As RouteValueDictionary,
    method As FormMethod,
    htmlAttributes As IDictionary(Of String, Object)
) As MvcForm

Parameters

Return Value

Type: System.Web.Mvc.Html.MvcForm

An opening <form> tag.

Remarks

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.

Examples

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">

Return to top