Compartir a través de


MvcForm Class

Represents an HTML form element in an MVC view.

Inheritance Hierarchy

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

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

Syntax

'Declaration
Public Class MvcForm _
    Implements IDisposable
public class MvcForm : IDisposable
public ref class MvcForm : IDisposable

The MvcForm type exposes the following members.

Constructors

  Name Description
Public method MvcForm(HttpResponseBase) Obsolete. Initializes a new instance of the MvcForm class using the specified HTTP response object.
Public method MvcForm(ViewContext) Initializes a new instance of the MvcForm class using the specified view context.

Top

Methods

  Name Description
Public method Dispose() Releases all resources that are used by the current instance of the MvcForm class.
Protected method Dispose(Boolean) Releases unmanaged and, optionally, managed resources used by the current instance of the MvcForm class.
Public method EndForm Ends the form and disposes of all form resources.
Public method Equals Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

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

Examples

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

<% End Using%>

<br /><br />

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

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

<% form.EndForm()%>
<% 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(); %>

Thread Safety

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

See Also

Reference

System.Web.Mvc.Html Namespace