Share via


HtmlHelper<TModel>.ValidationMessageFor<TResult> Method

Definition

Returns the validation message if an error exists in the ModelStateDictionary object for the specified expression.

public:
generic <typename TResult>
 virtual Microsoft::AspNetCore::Html::IHtmlContent ^ ValidationMessageFor(System::Linq::Expressions::Expression<Func<TModel, TResult> ^> ^ expression, System::String ^ message, System::Object ^ htmlAttributes, System::String ^ tag);
public Microsoft.AspNetCore.Html.IHtmlContent ValidationMessageFor<TResult> (System.Linq.Expressions.Expression<Func<TModel,TResult>> expression, string message, object htmlAttributes, string tag);
abstract member ValidationMessageFor : System.Linq.Expressions.Expression<Func<'Model, 'Result>> * string * obj * string -> Microsoft.AspNetCore.Html.IHtmlContent
override this.ValidationMessageFor : System.Linq.Expressions.Expression<Func<'Model, 'Result>> * string * obj * string -> Microsoft.AspNetCore.Html.IHtmlContent
Public Function ValidationMessageFor(Of TResult) (expression As Expression(Of Func(Of TModel, TResult)), message As String, htmlAttributes As Object, tag As String) As IHtmlContent

Type Parameters

TResult

The type of the expression result.

Parameters

expression
Expression<Func<TModel,TResult>>

An expression to be evaluated against the current model.

message
String

The message to be displayed. If null or empty, method extracts an error string from the ModelStateDictionary object. Message will always be visible but client-side validation may update the associated CSS class.

htmlAttributes
Object

An Object that contains the HTML attributes for the tag element. Alternatively, an IDictionary<TKey,TValue> instance containing the HTML attributes.

tag
String

The tag to wrap the message in the generated HTML. Its default value is ValidationMessageElement.

Returns

A new IHtmlContent containing the tag element. null if the expression is valid and client-side validation is disabled.

Implements

Applies to