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
htmlHelperHtmlHelperThe HTML helper instance that this method extends.
modelNamestringThe name of the property or model object that is being validated.
Exceptions
- ArgumentNullException
The
modelNameparameter 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
htmlHelperHtmlHelper<TModel>The HTML helper instance that this method extends.
expressionExpression<Func<TModel, TProperty>>An expression that identifies the object that contains the properties to render.
Type Parameters
TModelThe type of the model.
TPropertyThe 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
htmlHelperHtmlHelperThe HTML helper instance that this method extends.
modelNamestringThe 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
htmlHelperHtmlHelperThe HTML helper instance that this method extends.
modelNamestringThe name of the property or model object that is being validated.
htmlAttributesIDictionary<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
htmlHelperHtmlHelperThe HTML helper instance that this method operates on.
modelNamestringThe name of the entry being validated.
htmlAttributesIDictionary<string, object>An IDictionary<TKey, TValue> that contains the HTML attributes for the element.
tagstringThe 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
tagelement 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
htmlHelperHtmlHelperThe HTML helper instance that this method extends.
modelNamestringThe name of the property or model object that is being validated.
htmlAttributesobjectAn 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
htmlHelperHtmlHelperThe HTML helper instance that this method operates on.
modelNamestringThe name of the entry being validated.
htmlAttributesobjectAn object that contains the HTML attributes for the element.
tagstringThe 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
tagelement 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
htmlHelperHtmlHelperThe HTML helper instance that this method extends.
modelNamestringThe name of the property or model object that is being validated.
validationMessagestringThe 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
htmlHelperHtmlHelperThe HTML helper instance that this method extends.
modelNamestringThe name of the property or model object that is being validated.
validationMessagestringThe message to display if the specified field contains an error.
htmlAttributesIDictionary<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
htmlHelperHtmlHelperThe HTML helper instance that this method operates on.
modelNamestringThe name of the model object being validated.
validationMessagestringThe message to display if the specified entry contains an error.
htmlAttributesIDictionary<string, object>An IDictionary<TKey, TValue> that contains the HTML attributes for the element.
tagstringThe 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
tagelement 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
htmlHelperHtmlHelperThe HTML helper instance that this method extends.
modelNamestringThe name of the property or model object that is being validated.
validationMessagestringThe message to display if the specified field contains an error.
htmlAttributesobjectAn 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
htmlHelperHtmlHelperThe HTML helper instance that this method operates on.
modelNamestringThe name of the entry being validated.
validationMessagestringThe message to display if the specified entry contains an error.
htmlAttributesobjectAn object that contains the HTML attributes for the element.
tagstringThe 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
tagelement 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
htmlHelperHtmlHelperThe HTML helper instance that this method operates on.
modelNamestringThe name of the entry being validated.
validationMessagestringThe message to display if the specified entry contains an error.
tagstringThe 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
tagelement 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
htmlHelperHtmlHelper<TModel>The HTML helper instance that this method extends.
expressionExpression<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
TModelThe type of the model.
TPropertyThe 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
htmlHelperHtmlHelper<TModel>The HTML helper instance that this method extends.
expressionExpression<Func<TModel, TProperty>>An expression that identifies the object that contains the properties to render.
validationMessagestringThe 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
TModelThe type of the model.
TPropertyThe 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
htmlHelperHtmlHelper<TModel>The HTML helper instance that this method extends.
expressionExpression<Func<TModel, TProperty>>An expression that identifies the object that contains the properties to render.
validationMessagestringThe message to display if the specified field contains an error.
htmlAttributesIDictionary<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
TModelThe type of the model.
TPropertyThe 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
htmlHelperHtmlHelper<TModel>The HTML helper instance that this method operates on.
expressionExpression<Func<TModel, TProperty>>An expression that identifies the object that contains the properties to render.
validationMessagestringThe message to display if a validation error occurs.
htmlAttributesIDictionary<string, object>An IDictionary<TKey, TValue> that contains the HTML attributes for the element.
tagstringThe 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
tagelement that contains an error message.
Type Parameters
TModelThe type of the model.
TPropertyThe 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
htmlHelperHtmlHelper<TModel>The HTML helper instance that this method extends.
expressionExpression<Func<TModel, TProperty>>An expression that identifies the object that contains the properties to render.
validationMessagestringThe message to display if the specified field contains an error.
htmlAttributesobjectAn 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
TModelThe type of the model.
TPropertyThe 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
htmlHelperHtmlHelper<TModel>The HTML helper instance that this method operates on.
expressionExpression<Func<TModel, TProperty>>An expression that identifies the object that contains the properties to render.
validationMessagestringThe message to display if a validation error occurs.
htmlAttributesobjectAn object that contains the HTML attributes for the element.
tagstringThe 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
tagelement that contains an error message.
Type Parameters
TModelThe type of the model.
TPropertyThe 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
htmlHelperHtmlHelper<TModel>The HTML helper instance that this method operates on.
expressionExpression<Func<TModel, TProperty>>An expression that identifies the object that contains the properties to render.
validationMessagestringThe message to display if a validation error occurs.
tagstringThe 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
tagelement that contains an error message.
Type Parameters
TModelThe type of the model.
TPropertyThe 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
htmlHelperHtmlHelperThe 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
htmlHelperHtmlHelperThe HTML helper instance that this method extends.
excludePropertyErrorsbooltrue 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
htmlHelperHtmlHelperThe HTML helper instance that this method extends.
excludePropertyErrorsbooltrue to have the summary display model-level errors only, or false to have the summary display all errors.
messagestringThe 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
htmlHelperHtmlHelperThe HTML helper instance that this method extends.
excludePropertyErrorsbooltrue to have the summary display model-level errors only, or false to have the summary display all errors.
messagestringThe message to display with the validation summary.
htmlAttributesIDictionary<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
htmlHelperHtmlHelperexcludePropertyErrorsboolmessagestringhtmlAttributesIDictionary<string, object>headingTagstring
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
htmlHelperHtmlHelperThe HTML helper instance that this method extends.
excludePropertyErrorsbooltrue to have the summary display model-level errors only, or false to have the summary display all errors.
messagestringThe message to display with the validation summary.
htmlAttributesobjectAn 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
htmlHelperHtmlHelperexcludePropertyErrorsboolmessagestringhtmlAttributesobjectheadingTagstring
Returns
ValidationSummary(HtmlHelper, bool, string, string)
public static MvcHtmlString ValidationSummary(this HtmlHelper htmlHelper, bool excludePropertyErrors, string message, string headingTag)
Parameters
htmlHelperHtmlHelperexcludePropertyErrorsboolmessagestringheadingTagstring
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
htmlHelperHtmlHelperThe HMTL helper instance that this method extends.
messagestringThe 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
htmlHelperHtmlHelperThe HTML helper instance that this method extends.
messagestringThe message to display if the specified field contains an error.
htmlAttributesIDictionary<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
htmlHelperHtmlHelpermessagestringhtmlAttributesIDictionary<string, object>headingTagstring
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
htmlHelperHtmlHelperThe HTML helper instance that this method extends.
messagestringThe message to display if the specified field contains an error.
htmlAttributesobjectAn 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
htmlHelperHtmlHelpermessagestringhtmlAttributesobjectheadingTagstring
Returns
ValidationSummary(HtmlHelper, string, string)
public static MvcHtmlString ValidationSummary(this HtmlHelper htmlHelper, string message, string headingTag)
Parameters
htmlHelperHtmlHelpermessagestringheadingTagstring