ValidationExtensions.ValidationMessageFor Method

 

Returns the HTML markup for a validation-error message for each data field that is represented by the specified expression.

Namespace:   System.Web.Mvc.Html
Assembly:  System.Web.Mvc (in System.Web.Mvc.dll)

Overload List

Name Description
System_CAPS_pubmethodSystem_CAPS_static 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.

System_CAPS_pubmethodSystem_CAPS_static 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.

System_CAPS_pubmethodSystem_CAPS_static 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.

System_CAPS_pubmethodSystem_CAPS_static 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.

System_CAPS_pubmethodSystem_CAPS_static 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.

System_CAPS_pubmethodSystem_CAPS_static 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.

System_CAPS_pubmethodSystem_CAPS_static ValidationMessageFor<TModel, TProperty>(HtmlHelper<TModel>, Expression<Func<TModel, TProperty>>, String, String)

Returns the HTML markup for a validation-error message for the specified expression.

See Also

ValidationExtensions Class
System.Web.Mvc.Html Namespace

Return to top

ValidationExtensions.ValidationMessageFor<TModel, TProperty> Method (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.

Syntax

public static MvcHtmlString ValidationMessageFor<TModel, TProperty>(
    this HtmlHelper<TModel> htmlHelper,
    Expression<Func<TModel, TProperty>> expression
)
public:
generic<typename TModel, typename TProperty>
[ExtensionAttribute]
static MvcHtmlString^ ValidationMessageFor(
    HtmlHelper<TModel>^ htmlHelper,
    Expression<Func<TModel, TProperty>^>^ expression
)
static member ValidationMessageFor<'TModel, 'TProperty> : 
        htmlHelper:HtmlHelper<'TModel> *
        expression:Expression<Func<'TModel, 'TProperty>> -> MvcHtmlString
<ExtensionAttribute>
Public Shared Function ValidationMessageFor(Of TModel, TProperty) (
    htmlHelper As HtmlHelper(Of TModel),
    expression As Expression(Of Func(Of TModel, TProperty))
) As MvcHtmlString

Parameters

Return Value

Type: System.Web.Mvc.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.

Return to top

ValidationExtensions.ValidationMessageFor<TModel, TProperty> Method (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.

Syntax

public static MvcHtmlString ValidationMessageFor<TModel, TProperty>(
    this HtmlHelper<TModel> htmlHelper,
    Expression<Func<TModel, TProperty>> expression,
    string validationMessage
)
public:
generic<typename TModel, typename TProperty>
[ExtensionAttribute]
static MvcHtmlString^ ValidationMessageFor(
    HtmlHelper<TModel>^ htmlHelper,
    Expression<Func<TModel, TProperty>^>^ expression,
    String^ validationMessage
)
static member ValidationMessageFor<'TModel, 'TProperty> : 
        htmlHelper:HtmlHelper<'TModel> *
        expression:Expression<Func<'TModel, 'TProperty>> *
        validationMessage:string -> MvcHtmlString
<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

  • validationMessage
    Type: System.String

    The message to display if the specified field contains an error.

Return Value

Type: System.Web.Mvc.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.

Return to top

ValidationExtensions.ValidationMessageFor<TModel, TProperty> Method (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.

Syntax

public static MvcHtmlString ValidationMessageFor<TModel, TProperty>(
    this HtmlHelper<TModel> htmlHelper,
    Expression<Func<TModel, TProperty>> expression,
    string validationMessage,
    IDictionary<string, object> htmlAttributes
)
public:
generic<typename TModel, typename TProperty>
[ExtensionAttribute]
static MvcHtmlString^ ValidationMessageFor(
    HtmlHelper<TModel>^ htmlHelper,
    Expression<Func<TModel, TProperty>^>^ expression,
    String^ validationMessage,
    IDictionary<String^, Object^>^ htmlAttributes
)
static member ValidationMessageFor<'TModel, 'TProperty> : 
        htmlHelper:HtmlHelper<'TModel> *
        expression:Expression<Func<'TModel, 'TProperty>> *
        validationMessage:string *
        htmlAttributes:IDictionary<string, Object> -> MvcHtmlString
<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

  • validationMessage
    Type: System.String

    The message to display if the specified field contains an error.

Return Value

Type: System.Web.Mvc.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.

Return to top

ValidationExtensions.ValidationMessageFor<TModel, TProperty> Method (HtmlHelper<TModel>, Expression<Func<TModel, TProperty>>, String, IDictionary<String, Object>, String)

Returns the HTML markup for a validation-error message for the specified expression.

Syntax

public static MvcHtmlString ValidationMessageFor<TModel, TProperty>(
    this HtmlHelper<TModel> htmlHelper,
    Expression<Func<TModel, TProperty>> expression,
    string validationMessage,
    IDictionary<string, object> htmlAttributes,
    string tag
)
public:
generic<typename TModel, typename TProperty>
[ExtensionAttribute]
static MvcHtmlString^ ValidationMessageFor(
    HtmlHelper<TModel>^ htmlHelper,
    Expression<Func<TModel, TProperty>^>^ expression,
    String^ validationMessage,
    IDictionary<String^, Object^>^ htmlAttributes,
    String^ tag
)
static member ValidationMessageFor<'TModel, 'TProperty> : 
        htmlHelper:HtmlHelper<'TModel> *
        expression:Expression<Func<'TModel, 'TProperty>> *
        validationMessage:string *
        htmlAttributes:IDictionary<string, Object> *
        tag:string -> MvcHtmlString
<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

  • 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.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.

Return to top

ValidationExtensions.ValidationMessageFor<TModel, TProperty> Method (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.

Syntax

public static MvcHtmlString ValidationMessageFor<TModel, TProperty>(
    this HtmlHelper<TModel> htmlHelper,
    Expression<Func<TModel, TProperty>> expression,
    string validationMessage,
    object htmlAttributes
)
public:
generic<typename TModel, typename TProperty>
[ExtensionAttribute]
static MvcHtmlString^ ValidationMessageFor(
    HtmlHelper<TModel>^ htmlHelper,
    Expression<Func<TModel, TProperty>^>^ expression,
    String^ validationMessage,
    Object^ htmlAttributes
)
static member ValidationMessageFor<'TModel, 'TProperty> : 
        htmlHelper:HtmlHelper<'TModel> *
        expression:Expression<Func<'TModel, 'TProperty>> *
        validationMessage:string *
        htmlAttributes:Object -> MvcHtmlString
<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

  • 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.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.

Remarks

Client validation must be enabled.

Return to top

ValidationExtensions.ValidationMessageFor<TModel, TProperty> Method (HtmlHelper<TModel>, Expression<Func<TModel, TProperty>>, String, Object, String)

Returns the HTML markup for a validation-error message for the specified expression.

Syntax

public static MvcHtmlString ValidationMessageFor<TModel, TProperty>(
    this HtmlHelper<TModel> htmlHelper,
    Expression<Func<TModel, TProperty>> expression,
    string validationMessage,
    object htmlAttributes,
    string tag
)
public:
generic<typename TModel, typename TProperty>
[ExtensionAttribute]
static MvcHtmlString^ ValidationMessageFor(
    HtmlHelper<TModel>^ htmlHelper,
    Expression<Func<TModel, TProperty>^>^ expression,
    String^ validationMessage,
    Object^ htmlAttributes,
    String^ tag
)
static member ValidationMessageFor<'TModel, 'TProperty> : 
        htmlHelper:HtmlHelper<'TModel> *
        expression:Expression<Func<'TModel, 'TProperty>> *
        validationMessage:string *
        htmlAttributes:Object *
        tag:string -> MvcHtmlString
<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

  • 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.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.

Return to top

ValidationExtensions.ValidationMessageFor<TModel, TProperty> Method (HtmlHelper<TModel>, Expression<Func<TModel, TProperty>>, String, String)

Returns the HTML markup for a validation-error message for the specified expression.

Syntax

public static MvcHtmlString ValidationMessageFor<TModel, TProperty>(
    this HtmlHelper<TModel> htmlHelper,
    Expression<Func<TModel, TProperty>> expression,
    string validationMessage,
    string tag
)
public:
generic<typename TModel, typename TProperty>
[ExtensionAttribute]
static MvcHtmlString^ ValidationMessageFor(
    HtmlHelper<TModel>^ htmlHelper,
    Expression<Func<TModel, TProperty>^>^ expression,
    String^ validationMessage,
    String^ tag
)
static member ValidationMessageFor<'TModel, 'TProperty> : 
        htmlHelper:HtmlHelper<'TModel> *
        expression:Expression<Func<'TModel, 'TProperty>> *
        validationMessage:string *
        tag:string -> MvcHtmlString
<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

  • 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.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.

Return to top