MvcForm Class

Visual Studio 2010

Represents an HTML form element in an MVC view.

System.Object
  System.Web.Mvc.Html.MvcForm

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

public class MvcForm : IDisposable

The MvcForm type exposes the following members.

  NameDescription
Public methodMvcForm(HttpResponseBase) Obsolete. Initializes a new instance of the MvcForm class using the specified HTTP response object.
Public methodMvcForm(ViewContext)Initializes a new instance of the MvcForm class using the specified view context.
Top

  NameDescription
Public methodDispose()Releases all resources that are used by the current instance of the MvcForm class.
Protected methodDispose(Boolean)Releases unmanaged and, optionally, managed resources used by the current instance of the MvcForm class.
Public methodEndFormEnds the form and disposes of all form resources.
Public methodEqualsDetermines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

A MvcForm instance is returned by both the BeginForm and BeginRouteForm extension methods of the HtmlHelper and AjaxHelper classes.

This example shows two ways to create the same form in MVC. The first way uses the Using statement. The second way uses the MvcForm class directly.


<% using (Html.BeginForm("ProcessForm", "Home"))
   { %>

   Enter your name: <%= Html.TextBox("name") %>
   <input type="submit" value="Submit" />

<% } %>

<br /><br />

<% MvcForm form = Html.BeginForm("ProcessForm", "Home"); %>

       Enter your name: <%= Html.TextBox("name") %>
       <input type="submit" value="Submit" />

<% form.EndForm(); %>


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

ADD
Show: