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)

NameDescription
System_CAPS_pubmethodSystem_CAPS_staticBeginForm(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_staticBeginForm(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_staticBeginForm(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_staticBeginForm(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_staticBeginForm(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_staticBeginForm(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_staticBeginForm(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_staticBeginForm(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_staticBeginForm(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_staticBeginForm(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_staticBeginForm(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_staticBeginForm(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_staticBeginForm(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.

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.

public:
[ExtensionAttribute]
static MvcForm^ BeginForm(
	HtmlHelper^ htmlHelper
)

Parameters

htmlHelper
Type: System.Web.Mvc::HtmlHelper^

The HTML helper instance that this method extends.

Return Value

Type: System.Web.Mvc.Html::MvcForm^

An opening <form> tag.

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

public:
[ExtensionAttribute]
static MvcForm^ BeginForm(
	HtmlHelper^ htmlHelper,
	Object^ routeValues
)

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.

Return Value

Type: System.Web.Mvc.Html::MvcForm^

An opening <form> tag.

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

public:
[ExtensionAttribute]
static MvcForm^ BeginForm(
	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.

Return Value

Type: System.Web.Mvc.Html::MvcForm^

An opening <form> tag.

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

public:
[ExtensionAttribute]
static MvcForm^ BeginForm(
	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.

Return Value

Type: System.Web.Mvc.Html::MvcForm^

An opening <form> tag.

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

public:
[ExtensionAttribute]
static MvcForm^ BeginForm(
	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.

Return Value

Type: System.Web.Mvc.Html::MvcForm^

An opening <form> tag.

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

public:
[ExtensionAttribute]
static MvcForm^ BeginForm(
	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.

Return Value

Type: System.Web.Mvc.Html::MvcForm^

An opening <form> tag.

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

public:
[ExtensionAttribute]
static MvcForm^ BeginForm(
	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.

Return Value

Type: System.Web.Mvc.Html::MvcForm^

An opening <form> tag.

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

public:
[ExtensionAttribute]
static MvcForm^ BeginForm(
	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.

Return Value

Type: System.Web.Mvc.Html::MvcForm^

An opening <form> tag.

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

public:
[ExtensionAttribute]
static MvcForm^ BeginForm(
	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.

Return Value

Type: System.Web.Mvc.Html::MvcForm^

An opening <form> tag.

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

public:
[ExtensionAttribute]
static MvcForm^ BeginForm(
	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.

Return Value

Type: System.Web.Mvc.Html::MvcForm^

An opening <form> tag.

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:

No code example is currently available or this language may not be supported.

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.

public:
[ExtensionAttribute]
static MvcForm^ BeginForm(
	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.

Return Value

Type: System.Web.Mvc.Html::MvcForm^

An opening <form> tag.

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

public:
[ExtensionAttribute]
static MvcForm^ BeginForm(
	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.

Return Value

Type: System.Web.Mvc.Html::MvcForm^

An opening <form> tag.

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

public:
[ExtensionAttribute]
static MvcForm^ BeginForm(
	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.

Return Value

Type: System.Web.Mvc.Html::MvcForm^

An opening <form> tag.

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">
Return to top
Show: