Table of Contents

Class FormContext

Namespace
System.Web.Mvc
Assembly
System.Web.Mvc.dll

Encapsulates information that is required in order to validate and process the input data from an HTML form.

public class FormContext
Inheritance
FormContext
Inherited Members

Constructors

FormContext()

Initializes a new instance of the FormContext class.

public FormContext()

Properties

FieldValidators

Gets the field validators for the form.

public IDictionary<string, FieldValidationMetadata> FieldValidators { get; }

Property Value

IDictionary<string, FieldValidationMetadata>

A dictionary of field validators for the form.

FormId

Gets or sets the form identifier.

public string FormId { get; set; }

Property Value

string

The form identifier.

ReplaceValidationSummary

Determines whether client validation errors should be dynamically added to the validation summary.

public bool ReplaceValidationSummary { get; set; }

Property Value

bool

true if client validation errors should be added to the validation summary; otherwise, false.

ValidationSummaryId

Gets or sets the identifier for the validation summary.

public string ValidationSummaryId { get; set; }

Property Value

string

The identifier for the validation summary.

Methods

GetJsonValidationMetadata()

Returns a serialized object that contains the form identifier and field-validation values for the form.

public string GetJsonValidationMetadata()

Returns

string

A serialized object that contains the form identifier and field-validation values for the form.

GetValidationMetadataForField(string)

Returns the validation value for the specified input field.

public FieldValidationMetadata GetValidationMetadataForField(string fieldName)

Parameters

fieldName string

The name of the field to retrieve the validation value for.

Returns

FieldValidationMetadata

The value to validate the field input with.

Exceptions

ArgumentException

The fieldName parameter is either null or empty.

GetValidationMetadataForField(string, bool)

Returns the validation value for the specified input field and a value that indicates what to do if the validation value is not found.

public FieldValidationMetadata GetValidationMetadataForField(string fieldName, bool createIfNotFound)

Parameters

fieldName string

The name of the field to retrieve the validation value for.

createIfNotFound bool

true to create a validation value if one is not found; otherwise, false.

Returns

FieldValidationMetadata

The value to validate the field input with.

Exceptions

ArgumentException

The fieldName parameter is either null or empty.

RenderedField(string)

Returns a value that indicates whether the specified field has been rendered in the form.

public bool RenderedField(string fieldName)

Parameters

fieldName string

The field name.

Returns

bool

true if the field has been rendered; otherwise, false.

RenderedField(string, bool)

Sets a value that indicates whether the specified field has been rendered in the form.

public void RenderedField(string fieldName, bool value)

Parameters

fieldName string

The field name.

value bool

true to specify that the field has been rendered in the form; otherwise, false.