1 /* ****************************************************************************
\r
3 * Copyright (c) Microsoft Corporation. All rights reserved.
\r
5 * This software is subject to the Microsoft Public License (Ms-PL).
\r
6 * A copy of the license can be found in the license.htm file included
\r
7 * in this distribution.
\r
9 * You must not remove this notice, or any other, from this software.
\r
11 * ***************************************************************************/
\r
13 namespace System.Web.Mvc.Html {
\r
17 public class MvcForm : IDisposable {
\r
19 private bool _disposed;
\r
20 private readonly FormContext _originalFormContext;
\r
21 private readonly ViewContext _viewContext;
\r
22 private readonly TextWriter _writer;
\r
24 [Obsolete("The recommended alternative is the constructor MvcForm(ViewContext viewContext).", true /* error */)]
\r
25 public MvcForm(HttpResponseBase httpResponse) {
\r
26 if (httpResponse == null) {
\r
27 throw new ArgumentNullException("httpResponse");
\r
30 _writer = httpResponse.Output;
\r
33 public MvcForm(ViewContext viewContext) {
\r
34 if (viewContext == null) {
\r
35 throw new ArgumentNullException("viewContext");
\r
38 _viewContext = viewContext;
\r
39 _writer = viewContext.Writer;
\r
41 // push the new FormContext
\r
42 _originalFormContext = viewContext.FormContext;
\r
43 viewContext.FormContext = new FormContext();
\r
46 public void Dispose() {
\r
47 Dispose(true /* disposing */);
\r
48 GC.SuppressFinalize(this);
\r
51 protected virtual void Dispose(bool disposing) {
\r
54 _writer.Write("</form>");
\r
56 // output client validation and restore the original form context
\r
57 if (_viewContext != null) {
\r
58 _viewContext.OutputClientValidation();
\r
59 _viewContext.FormContext = _originalFormContext;
\r
64 public void EndForm() {
\r