ValidationExtensions.ValidationMessageFor Method
Returns the HTML markup for a validation-error message for each data field that is represented by the specified expression.
Assembly: System.Web.Mvc (in System.Web.Mvc.dll)
ValidationExtensions.ValidationMessageFor(Of TModel, TProperty) Method (HtmlHelper(Of TModel), Expression(Of Func(Of TModel, TProperty)))
Returns the HTML markup for a validation-error message for each data field that is represented by the specified expression.
<ExtensionAttribute> Public Shared Function ValidationMessageFor(Of TModel, TProperty) ( htmlHelper As HtmlHelper(Of TModel), expression As Expression(Of Func(Of TModel, TProperty)) ) As MvcHtmlString
Parameters
- htmlHelper
-
Type:
System.Web.Mvc.HtmlHelper(Of TModel)
The HTML helper instance that this method extends.
- expression
-
Type:
System.Linq.Expressions.Expression(Of Func(Of TModel, TProperty))
An expression that identifies the object that contains the properties to render.
Return Value
Type: System.Web.Mvc.MvcHtmlStringIf 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.
ValidationExtensions.ValidationMessageFor(Of TModel, TProperty) Method (HtmlHelper(Of TModel), Expression(Of Func(Of 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.
<ExtensionAttribute> Public Shared Function ValidationMessageFor(Of TModel, TProperty) ( htmlHelper As HtmlHelper(Of TModel), expression As Expression(Of Func(Of TModel, TProperty)), validationMessage As String ) As MvcHtmlString
Parameters
- htmlHelper
-
Type:
System.Web.Mvc.HtmlHelper(Of TModel)
The HTML helper instance that this method extends.
- expression
-
Type:
System.Linq.Expressions.Expression(Of Func(Of TModel, TProperty))
An expression that identifies the object that contains the properties to render.
- validationMessage
-
Type:
System.String
The message to display if the specified field contains an error.
Return Value
Type: System.Web.Mvc.MvcHtmlStringIf 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.
ValidationExtensions.ValidationMessageFor(Of TModel, TProperty) Method (HtmlHelper(Of TModel), Expression(Of Func(Of TModel, TProperty)), String, IDictionary(Of 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.
<ExtensionAttribute> Public Shared Function ValidationMessageFor(Of TModel, TProperty) ( htmlHelper As HtmlHelper(Of TModel), expression As Expression(Of Func(Of TModel, TProperty)), validationMessage As String, htmlAttributes As IDictionary(Of String, Object) ) As MvcHtmlString
Parameters
- htmlHelper
-
Type:
System.Web.Mvc.HtmlHelper(Of TModel)
The HTML helper instance that this method extends.
- expression
-
Type:
System.Linq.Expressions.Expression(Of Func(Of TModel, TProperty))
An expression that identifies the object that contains the properties to render.
- validationMessage
-
Type:
System.String
The message to display if the specified field contains an error.
- htmlAttributes
-
Type:
System.Collections.Generic.IDictionary(Of String, Object)
An object that contains the HTML attributes for the element.
Return Value
Type: System.Web.Mvc.MvcHtmlStringIf 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.
ValidationExtensions.ValidationMessageFor(Of TModel, TProperty) Method (HtmlHelper(Of TModel), Expression(Of Func(Of TModel, TProperty)), String, IDictionary(Of String, Object), String)
Returns the HTML markup for a validation-error message for the specified expression.
<ExtensionAttribute> Public Shared Function ValidationMessageFor(Of TModel, TProperty) ( htmlHelper As HtmlHelper(Of TModel), expression As Expression(Of Func(Of TModel, TProperty)), validationMessage As String, htmlAttributes As IDictionary(Of String, Object), tag As String ) As MvcHtmlString
Parameters
- htmlHelper
-
Type:
System.Web.Mvc.HtmlHelper(Of TModel)
The HTML helper instance that this method operates on.
- expression
-
Type:
System.Linq.Expressions.Expression(Of Func(Of TModel, TProperty))
An expression that identifies the object that contains the properties to render.
- validationMessage
-
Type:
System.String
The message to display if a validation error occurs.
- htmlAttributes
-
Type:
System.Collections.Generic.IDictionary(Of String, Object)
An IDictionary(Of TKey, TValue) that contains the HTML attributes for the element.
- tag
-
Type:
System.String
The tag to be set for the wrapping HTML element of the validation message.
Return Value
Type: System.Web.Mvc.MvcHtmlStringnull 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.
ValidationExtensions.ValidationMessageFor(Of TModel, TProperty) Method (HtmlHelper(Of TModel), Expression(Of Func(Of 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.
<ExtensionAttribute> Public Shared Function ValidationMessageFor(Of TModel, TProperty) ( htmlHelper As HtmlHelper(Of TModel), expression As Expression(Of Func(Of TModel, TProperty)), validationMessage As String, htmlAttributes As Object ) As MvcHtmlString
Parameters
- htmlHelper
-
Type:
System.Web.Mvc.HtmlHelper(Of TModel)
The HTML helper instance that this method extends.
- expression
-
Type:
System.Linq.Expressions.Expression(Of Func(Of TModel, TProperty))
An expression that identifies the object that contains the properties to render.
- validationMessage
-
Type:
System.String
The message to display if the specified field contains an error.
- htmlAttributes
-
Type:
System.Object
An object that contains the HTML attributes for the element.
Return Value
Type: System.Web.Mvc.MvcHtmlStringIf 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.
Client validation must be enabled.
ValidationExtensions.ValidationMessageFor(Of TModel, TProperty) Method (HtmlHelper(Of TModel), Expression(Of Func(Of TModel, TProperty)), String, Object, String)
Returns the HTML markup for a validation-error message for the specified expression.
<ExtensionAttribute> Public Shared Function ValidationMessageFor(Of TModel, TProperty) ( htmlHelper As HtmlHelper(Of TModel), expression As Expression(Of Func(Of TModel, TProperty)), validationMessage As String, htmlAttributes As Object, tag As String ) As MvcHtmlString
Parameters
- htmlHelper
-
Type:
System.Web.Mvc.HtmlHelper(Of TModel)
The HTML helper instance that this method operates on.
- expression
-
Type:
System.Linq.Expressions.Expression(Of Func(Of TModel, TProperty))
An expression that identifies the object that contains the properties to render.
- validationMessage
-
Type:
System.String
The message to display if a validation error occurs.
- htmlAttributes
-
Type:
System.Object
An object that contains the HTML attributes for the element.
- tag
-
Type:
System.String
The tag to be set for the wrapping HTML element of the validation message.
Return Value
Type: System.Web.Mvc.MvcHtmlStringnull 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.
ValidationExtensions.ValidationMessageFor(Of TModel, TProperty) Method (HtmlHelper(Of TModel), Expression(Of Func(Of TModel, TProperty)), String, String)
Returns the HTML markup for a validation-error message for the specified expression.
<ExtensionAttribute> Public Shared Function ValidationMessageFor(Of TModel, TProperty) ( htmlHelper As HtmlHelper(Of TModel), expression As Expression(Of Func(Of TModel, TProperty)), validationMessage As String, tag As String ) As MvcHtmlString
Parameters
- htmlHelper
-
Type:
System.Web.Mvc.HtmlHelper(Of TModel)
The HTML helper instance that this method operates on.
- expression
-
Type:
System.Linq.Expressions.Expression(Of Func(Of TModel, TProperty))
An expression that identifies the object that contains the properties to render.
- validationMessage
-
Type:
System.String
The message to display if a validation error occurs.
- tag
-
Type:
System.String
The tag to be set for the wrapping HTML element of the validation message.
Return Value
Type: System.Web.Mvc.MvcHtmlStringnull 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.

