Class ValidationExtensions
Provides support for validating the input from an HTML form.
public static class ValidationExtensions
- Inheritance
-
ValidationExtensions
- Inherited Members
Properties
ResourceClassKey
Gets or sets the name of the resource file (class key) that contains localized string values.
public static string ResourceClassKey { get; set; }
Property Value
- string
The name of the resource file (class key).
Methods
Validate(HtmlHelper, string)
Retrieves the validation metadata for the specified model and applies each rule to the data field.
public static void Validate(this HtmlHelper htmlHelper, string modelName)
Parameters
htmlHelper
HtmlHelperThe HTML helper instance that this method extends.
modelName
stringThe name of the property or model object that is being validated.
Exceptions
- ArgumentNullException
The
modelName
parameter is null.
ValidateFor<TModel, TProperty>(HtmlHelper<TModel>, Expression<Func<TModel, TProperty>>)
Retrieves the validation metadata for the specified model and applies each rule to the data field.
public static void ValidateFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression)
Parameters
htmlHelper
HtmlHelper<TModel>The HTML helper instance that this method extends.
expression
Expression<Func<TModel, TProperty>>An expression that identifies the object that contains the properties to render.
Type Parameters
TModel
The type of the model.
TProperty
The type of the property.
ValidationMessage(HtmlHelper, string)
Displays a validation message if an error exists for the specified field in the ModelStateDictionary object.
public static MvcHtmlString ValidationMessage(this HtmlHelper htmlHelper, string modelName)
Parameters
htmlHelper
HtmlHelperThe HTML helper instance that this method extends.
modelName
stringThe name of the property or model object that is being validated.
Returns
- MvcHtmlString
If the property or object is valid, an empty string; otherwise, a span element that contains an error message.
ValidationMessage(HtmlHelper, string, IDictionary<string, object>)
Displays a validation message if an error exists for the specified field in the ModelStateDictionary object.
public static MvcHtmlString ValidationMessage(this HtmlHelper htmlHelper, string modelName, IDictionary<string, object> htmlAttributes)
Parameters
htmlHelper
HtmlHelperThe HTML helper instance that this method extends.
modelName
stringThe name of the property or model object that is being validated.
htmlAttributes
IDictionary<string, object>An object that contains the HTML attributes for the element.
Returns
- MvcHtmlString
If the property or object is valid, an empty string; otherwise, a span element that contains an error message.
ValidationMessage(HtmlHelper, string, IDictionary<string, object>, string)
Displays a validation message if an error exists for the specified entry in the ModelStateDictionary object.
public static MvcHtmlString ValidationMessage(this HtmlHelper htmlHelper, string modelName, IDictionary<string, object> htmlAttributes, string tag)
Parameters
htmlHelper
HtmlHelperThe HTML helper instance that this method operates on.
modelName
stringThe name of the entry being validated.
htmlAttributes
IDictionary<string, object>An IDictionary<TKey, TValue> that contains the HTML attributes for the element.
tag
stringThe tag to be set for the wrapping HTML element of the validation message.
Returns
- MvcHtmlString
null if the entry is valid and client-side validation is disabled. Otherwise, a
tag
element that contains an error message.
ValidationMessage(HtmlHelper, string, object)
Displays a validation message if an error exists for the specified field in the ModelStateDictionary object.
public static MvcHtmlString ValidationMessage(this HtmlHelper htmlHelper, string modelName, object htmlAttributes)
Parameters
htmlHelper
HtmlHelperThe HTML helper instance that this method extends.
modelName
stringThe name of the property or model object that is being validated.
htmlAttributes
objectAn object that contains the HTML attributes for the element.
Returns
- MvcHtmlString
If the property or object is valid, an empty string; otherwise, a span element that contains an error message.
ValidationMessage(HtmlHelper, string, object, string)
Displays a validation message if an error exists for the specified entry in the ModelStateDictionary object.
public static MvcHtmlString ValidationMessage(this HtmlHelper htmlHelper, string modelName, object htmlAttributes, string tag)
Parameters
htmlHelper
HtmlHelperThe HTML helper instance that this method operates on.
modelName
stringThe name of the entry being validated.
htmlAttributes
objectAn object that contains the HTML attributes for the element.
tag
stringThe tag to be set for the wrapping HTML element of the validation message.
Returns
- MvcHtmlString
null if the entry is valid and client-side validation is disabled. Otherwise, a
tag
element that contains an error message.
ValidationMessage(HtmlHelper, string, string)
Displays a validation message if an error exists for the specified field in the ModelStateDictionary object.
public static MvcHtmlString ValidationMessage(this HtmlHelper htmlHelper, string modelName, string validationMessage)
Parameters
htmlHelper
HtmlHelperThe HTML helper instance that this method extends.
modelName
stringThe name of the property or model object that is being validated.
validationMessage
stringThe message to display if the specified field contains an error.
Returns
- MvcHtmlString
If the property or object is valid, an empty string; otherwise, a span element that contains an error message.
ValidationMessage(HtmlHelper, string, string, IDictionary<string, object>)
Displays a validation message if an error exists for the specified field in the ModelStateDictionary object.
public static MvcHtmlString ValidationMessage(this HtmlHelper htmlHelper, string modelName, string validationMessage, IDictionary<string, object> htmlAttributes)
Parameters
htmlHelper
HtmlHelperThe HTML helper instance that this method extends.
modelName
stringThe name of the property or model object that is being validated.
validationMessage
stringThe message to display if the specified field contains an error.
htmlAttributes
IDictionary<string, object>An object that contains the HTML attributes for the element.
Returns
- MvcHtmlString
If the property or object is valid, an empty string; otherwise, a span element that contains an error message.
ValidationMessage(HtmlHelper, string, string, IDictionary<string, object>, string)
Displays a validation message if an error exists for the specified entry in the ModelStateDictionary object.
public static MvcHtmlString ValidationMessage(this HtmlHelper htmlHelper, string modelName, string validationMessage, IDictionary<string, object> htmlAttributes, string tag)
Parameters
htmlHelper
HtmlHelperThe HTML helper instance that this method operates on.
modelName
stringThe name of the model object being validated.
validationMessage
stringThe message to display if the specified entry contains an error.
htmlAttributes
IDictionary<string, object>An IDictionary<TKey, TValue> that contains the HTML attributes for the element.
tag
stringThe tag to be set for the wrapping HTML element of the validation message.
Returns
- MvcHtmlString
null if the model object is valid and client-side validation is disabled. Otherwise, a
tag
element that contains an error message.
ValidationMessage(HtmlHelper, string, string, object)
Displays a validation message if an error exists for the specified field in the ModelStateDictionary object.
public static MvcHtmlString ValidationMessage(this HtmlHelper htmlHelper, string modelName, string validationMessage, object htmlAttributes)
Parameters
htmlHelper
HtmlHelperThe HTML helper instance that this method extends.
modelName
stringThe name of the property or model object that is being validated.
validationMessage
stringThe message to display if the specified field contains an error.
htmlAttributes
objectAn object that contains the HTML attributes for the element.
Returns
- MvcHtmlString
If the property or object is valid, an empty string; otherwise, a span element that contains an error message.
ValidationMessage(HtmlHelper, string, string, object, string)
Displays a validation message if an error exists for the specified entry in the ModelStateDictionary object.
public static MvcHtmlString ValidationMessage(this HtmlHelper htmlHelper, string modelName, string validationMessage, object htmlAttributes, string tag)
Parameters
htmlHelper
HtmlHelperThe HTML helper instance that this method operates on.
modelName
stringThe name of the entry being validated.
validationMessage
stringThe message to display if the specified entry contains an error.
htmlAttributes
objectAn object that contains the HTML attributes for the element.
tag
stringThe tag to be set for the wrapping HTML element of the validation message.
Returns
- MvcHtmlString
null if the entry is valid and client-side validation is disabled. Otherwise, a
tag
element that contains an error message.
ValidationMessage(HtmlHelper, string, string, string)
Displays a validation message if an error exists for the specified entry in the ModelStateDictionary object.
public static MvcHtmlString ValidationMessage(this HtmlHelper htmlHelper, string modelName, string validationMessage, string tag)
Parameters
htmlHelper
HtmlHelperThe HTML helper instance that this method operates on.
modelName
stringThe name of the entry being validated.
validationMessage
stringThe message to display if the specified entry contains an error.
tag
stringThe tag to be set for the wrapping HTML element of the validation message.
Returns
- MvcHtmlString
null if the entry is valid and client-side validation is disabled. Otherwise, a
tag
element that contains an error message.
ValidationMessageFor<TModel, TProperty>(HtmlHelper<TModel>, Expression<Func<TModel, TProperty>>)
Returns the HTML markup for a validation-error message for each data field that is represented by the specified expression.
public static MvcHtmlString ValidationMessageFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression)
Parameters
htmlHelper
HtmlHelper<TModel>The HTML helper instance that this method extends.
expression
Expression<Func<TModel, TProperty>>An expression that identifies the object that contains the properties to render.
Returns
- MvcHtmlString
If the property or object is valid, an empty string; otherwise, a span element that contains an error message.
Type Parameters
TModel
The type of the model.
TProperty
The type of the property.
ValidationMessageFor<TModel, TProperty>(HtmlHelper<TModel>, Expression<Func<TModel, TProperty>>, string)
Returns the HTML markup for a validation-error message for each data field that is represented by the specified expression, using the specified message.
public static MvcHtmlString ValidationMessageFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, string validationMessage)
Parameters
htmlHelper
HtmlHelper<TModel>The HTML helper instance that this method extends.
expression
Expression<Func<TModel, TProperty>>An expression that identifies the object that contains the properties to render.
validationMessage
stringThe message to display if the specified field contains an error.
Returns
- MvcHtmlString
If the property or object is valid, an empty string; otherwise, a span element that contains an error message.
Type Parameters
TModel
The type of the model.
TProperty
The type of the property.
ValidationMessageFor<TModel, TProperty>(HtmlHelper<TModel>, Expression<Func<TModel, TProperty>>, string, IDictionary<string, object>)
Returns the HTML markup for a validation-error message for each data field that is represented by the specified expression, using the specified message and HTML attributes.
public static MvcHtmlString ValidationMessageFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, string validationMessage, IDictionary<string, object> htmlAttributes)
Parameters
htmlHelper
HtmlHelper<TModel>The HTML helper instance that this method extends.
expression
Expression<Func<TModel, TProperty>>An expression that identifies the object that contains the properties to render.
validationMessage
stringThe message to display if the specified field contains an error.
htmlAttributes
IDictionary<string, object>An object that contains the HTML attributes for the element.
Returns
- MvcHtmlString
If the property or object is valid, an empty string; otherwise, a span element that contains an error message.
Type Parameters
TModel
The type of the model.
TProperty
The type of the property.
ValidationMessageFor<TModel, TProperty>(HtmlHelper<TModel>, Expression<Func<TModel, TProperty>>, string, IDictionary<string, object>, string)
Returns the HTML markup for a validation-error message for the specified expression.
public static MvcHtmlString ValidationMessageFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, string validationMessage, IDictionary<string, object> htmlAttributes, string tag)
Parameters
htmlHelper
HtmlHelper<TModel>The HTML helper instance that this method operates on.
expression
Expression<Func<TModel, TProperty>>An expression that identifies the object that contains the properties to render.
validationMessage
stringThe message to display if a validation error occurs.
htmlAttributes
IDictionary<string, object>An IDictionary<TKey, TValue> that contains the HTML attributes for the element.
tag
stringThe tag to be set for the wrapping HTML element of the validation message.
Returns
- MvcHtmlString
null if the model object is valid and client-side validation is disabled. Otherwise, a
tag
element that contains an error message.
Type Parameters
TModel
The type of the model.
TProperty
The type of the property.
ValidationMessageFor<TModel, TProperty>(HtmlHelper<TModel>, Expression<Func<TModel, TProperty>>, string, object)
Returns the HTML markup for a validation-error message for each data field that is represented by the specified expression, using the specified message and HTML attributes.
public static MvcHtmlString ValidationMessageFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, string validationMessage, object htmlAttributes)
Parameters
htmlHelper
HtmlHelper<TModel>The HTML helper instance that this method extends.
expression
Expression<Func<TModel, TProperty>>An expression that identifies the object that contains the properties to render.
validationMessage
stringThe message to display if the specified field contains an error.
htmlAttributes
objectAn object that contains the HTML attributes for the element.
Returns
- MvcHtmlString
If the property or object is valid, an empty string; otherwise, a span element that contains an error message.
Type Parameters
TModel
The type of the model.
TProperty
The type of the property.
ValidationMessageFor<TModel, TProperty>(HtmlHelper<TModel>, Expression<Func<TModel, TProperty>>, string, object, string)
Returns the HTML markup for a validation-error message for the specified expression.
public static MvcHtmlString ValidationMessageFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, string validationMessage, object htmlAttributes, string tag)
Parameters
htmlHelper
HtmlHelper<TModel>The HTML helper instance that this method operates on.
expression
Expression<Func<TModel, TProperty>>An expression that identifies the object that contains the properties to render.
validationMessage
stringThe message to display if a validation error occurs.
htmlAttributes
objectAn object that contains the HTML attributes for the element.
tag
stringThe tag to be set for the wrapping HTML element of the validation message.
Returns
- MvcHtmlString
null if the model object is valid and client-side validation is disabled. Otherwise, a
tag
element that contains an error message.
Type Parameters
TModel
The type of the model.
TProperty
The type of the property.
ValidationMessageFor<TModel, TProperty>(HtmlHelper<TModel>, Expression<Func<TModel, TProperty>>, string, string)
Returns the HTML markup for a validation-error message for the specified expression.
public static MvcHtmlString ValidationMessageFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, string validationMessage, string tag)
Parameters
htmlHelper
HtmlHelper<TModel>The HTML helper instance that this method operates on.
expression
Expression<Func<TModel, TProperty>>An expression that identifies the object that contains the properties to render.
validationMessage
stringThe message to display if a validation error occurs.
tag
stringThe tag to be set for the wrapping HTML element of the validation message.
Returns
- MvcHtmlString
null if the model object is valid and client-side validation is disabled. Otherwise, a
tag
element that contains an error message.
Type Parameters
TModel
The type of the model.
TProperty
The type of the property.
ValidationSummary(HtmlHelper)
Returns an unordered list (ul element) of validation messages that are in the ModelStateDictionary object.
public static MvcHtmlString ValidationSummary(this HtmlHelper htmlHelper)
Parameters
htmlHelper
HtmlHelperThe HTML helper instance that this method extends.
Returns
- MvcHtmlString
A string that contains an unordered list (ul element) of validation messages.
ValidationSummary(HtmlHelper, bool)
Returns an unordered list (ul element) of validation messages that are in the ModelStateDictionary object and optionally displays only model-level errors.
public static MvcHtmlString ValidationSummary(this HtmlHelper htmlHelper, bool excludePropertyErrors)
Parameters
htmlHelper
HtmlHelperThe HTML helper instance that this method extends.
excludePropertyErrors
booltrue to have the summary display model-level errors only, or false to have the summary display all errors.
Returns
- MvcHtmlString
A string that contains an unordered list (ul element) of validation messages.
ValidationSummary(HtmlHelper, bool, string)
Returns an unordered list (ul element) of validation messages that are in the ModelStateDictionary object and optionally displays only model-level errors.
public static MvcHtmlString ValidationSummary(this HtmlHelper htmlHelper, bool excludePropertyErrors, string message)
Parameters
htmlHelper
HtmlHelperThe HTML helper instance that this method extends.
excludePropertyErrors
booltrue to have the summary display model-level errors only, or false to have the summary display all errors.
message
stringThe message to display with the validation summary.
Returns
- MvcHtmlString
A string that contains an unordered list (ul element) of validation messages.
ValidationSummary(HtmlHelper, bool, string, IDictionary<string, object>)
Returns an unordered list (ul element) of validation messages that are in the ModelStateDictionary object and optionally displays only model-level errors.
public static MvcHtmlString ValidationSummary(this HtmlHelper htmlHelper, bool excludePropertyErrors, string message, IDictionary<string, object> htmlAttributes)
Parameters
htmlHelper
HtmlHelperThe HTML helper instance that this method extends.
excludePropertyErrors
booltrue to have the summary display model-level errors only, or false to have the summary display all errors.
message
stringThe message to display with the validation summary.
htmlAttributes
IDictionary<string, object>A dictionary that contains the HTML attributes for the element.
Returns
- MvcHtmlString
A string that contains an unordered list (ul element) of validation messages.
ValidationSummary(HtmlHelper, bool, string, IDictionary<string, object>, string)
public static MvcHtmlString ValidationSummary(this HtmlHelper htmlHelper, bool excludePropertyErrors, string message, IDictionary<string, object> htmlAttributes, string headingTag)
Parameters
htmlHelper
HtmlHelperexcludePropertyErrors
boolmessage
stringhtmlAttributes
IDictionary<string, object>headingTag
string
Returns
ValidationSummary(HtmlHelper, bool, string, object)
Returns an unordered list (ul element) of validation messages that are in the ModelStateDictionary object and optionally displays only model-level errors.
public static MvcHtmlString ValidationSummary(this HtmlHelper htmlHelper, bool excludePropertyErrors, string message, object htmlAttributes)
Parameters
htmlHelper
HtmlHelperThe HTML helper instance that this method extends.
excludePropertyErrors
booltrue to have the summary display model-level errors only, or false to have the summary display all errors.
message
stringThe message to display with the validation summary.
htmlAttributes
objectAn object that contains the HTML attributes for the element.
Returns
- MvcHtmlString
A string that contains an unordered list (ul element) of validation messages.
ValidationSummary(HtmlHelper, bool, string, object, string)
public static MvcHtmlString ValidationSummary(this HtmlHelper htmlHelper, bool excludePropertyErrors, string message, object htmlAttributes, string headingTag)
Parameters
htmlHelper
HtmlHelperexcludePropertyErrors
boolmessage
stringhtmlAttributes
objectheadingTag
string
Returns
ValidationSummary(HtmlHelper, bool, string, string)
public static MvcHtmlString ValidationSummary(this HtmlHelper htmlHelper, bool excludePropertyErrors, string message, string headingTag)
Parameters
htmlHelper
HtmlHelperexcludePropertyErrors
boolmessage
stringheadingTag
string
Returns
ValidationSummary(HtmlHelper, string)
Returns an unordered list (ul element) of validation messages that are in the ModelStateDictionary object.
public static MvcHtmlString ValidationSummary(this HtmlHelper htmlHelper, string message)
Parameters
htmlHelper
HtmlHelperThe HMTL helper instance that this method extends.
message
stringThe message to display if the specified field contains an error.
Returns
- MvcHtmlString
A string that contains an unordered list (ul element) of validation messages.
ValidationSummary(HtmlHelper, string, IDictionary<string, object>)
Returns an unordered list (ul element) of validation messages that are in the ModelStateDictionary object.
public static MvcHtmlString ValidationSummary(this HtmlHelper htmlHelper, string message, IDictionary<string, object> htmlAttributes)
Parameters
htmlHelper
HtmlHelperThe HTML helper instance that this method extends.
message
stringThe message to display if the specified field contains an error.
htmlAttributes
IDictionary<string, object>A dictionary that contains the HTML attributes for the element.
Returns
- MvcHtmlString
A string that contains an unordered list (ul element) of validation messages.
ValidationSummary(HtmlHelper, string, IDictionary<string, object>, string)
public static MvcHtmlString ValidationSummary(this HtmlHelper htmlHelper, string message, IDictionary<string, object> htmlAttributes, string headingTag)
Parameters
htmlHelper
HtmlHelpermessage
stringhtmlAttributes
IDictionary<string, object>headingTag
string
Returns
ValidationSummary(HtmlHelper, string, object)
Returns an unordered list (ul element) of validation messages in the ModelStateDictionary object.
public static MvcHtmlString ValidationSummary(this HtmlHelper htmlHelper, string message, object htmlAttributes)
Parameters
htmlHelper
HtmlHelperThe HTML helper instance that this method extends.
message
stringThe message to display if the specified field contains an error.
htmlAttributes
objectAn object that contains the HTML attributes for the element.
Returns
- MvcHtmlString
A string that contains an unordered list (ul element) of validation messages.
ValidationSummary(HtmlHelper, string, object, string)
public static MvcHtmlString ValidationSummary(this HtmlHelper htmlHelper, string message, object htmlAttributes, string headingTag)
Parameters
htmlHelper
HtmlHelpermessage
stringhtmlAttributes
objectheadingTag
string
Returns
ValidationSummary(HtmlHelper, string, string)
public static MvcHtmlString ValidationSummary(this HtmlHelper htmlHelper, string message, string headingTag)
Parameters
htmlHelper
HtmlHelpermessage
stringheadingTag
string