HtmlHelperValidationExtensions Class¶
Validation-related extensions for Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper and Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper`1.
- Namespace
Microsoft.AspNetCore.Mvc.Rendering- Assemblies
- Microsoft.AspNetCore.Mvc.ViewFeatures
Syntax¶
public class HtmlHelperValidationExtensions
-
class
Microsoft.AspNetCore.Mvc.Rendering.HtmlHelperValidationExtensions
Methods¶
-
ValidationMessage(Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper, System.String)¶ Returns the validation message if an error exists in the
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionaryobject for the specified <em>expression</em>.Arguments: - htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper) – The
Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelperinstance this method extends. - expression (System.String) – Expression name, relative to the current model.
Return type: Returns: A new
Microsoft.AspNetCore.Html.IHtmlContentcontaining aMicrosoft.AspNetCore.Mvc.Rendering.ViewContext.ValidationMessageElementelement. <code>null</code> if the <em>expression</em> is valid and client-side validation is disabled.public static IHtmlContent ValidationMessage(this IHtmlHelper htmlHelper, string expression)
- htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper) – The
-
ValidationMessage(Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper, System.String, System.Object) Returns the validation message if an error exists in the
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionaryobject for the specified <em>expression</em>.Arguments: - htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper) – The
Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelperinstance this method extends. - expression (System.String) – Expression name, relative to the current model.
- htmlAttributes (System.Object) – An
System.Objectthat contains the HTML attributes for the (Microsoft.AspNetCore.Mvc.Rendering.ViewContext.ValidationMessageElement) element. Alternatively, anSystem.Collections.Generic.IDictionary`2instance containing the HTML attributes.
Return type: Returns: A new
Microsoft.AspNetCore.Html.IHtmlContentcontaining aMicrosoft.AspNetCore.Mvc.Rendering.ViewContext.ValidationMessageElementelement. <code>null</code> if the <em>expression</em> is valid and client-side validation is disabled.public static IHtmlContent ValidationMessage(this IHtmlHelper htmlHelper, string expression, object htmlAttributes)
- htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper) – The
-
ValidationMessage(Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper, System.String, System.String) Returns the validation message if an error exists in the
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionaryobject for the specified <em>expression</em>.Arguments: - htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper) – The
Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelperinstance this method extends. - expression (System.String) – Expression name, relative to the current model.
- message (System.String) – The message to be displayed. If <code>null</code> or empty, method extracts an error string from the
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionaryobject. Message will always be visible but client-side validation may update the associated CSS class.
Return type: Returns: A new
Microsoft.AspNetCore.Html.IHtmlContentcontaining aMicrosoft.AspNetCore.Mvc.Rendering.ViewContext.ValidationMessageElementelement. <code>null</code> if the <em>expression</em> is valid and client-side validation is disabled.public static IHtmlContent ValidationMessage(this IHtmlHelper htmlHelper, string expression, string message)
- htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper) – The
-
ValidationMessage(Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper, System.String, System.String, System.Object) Returns the validation message if an error exists in the
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionaryobject for the specified <em>expression</em>.Arguments: - htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper) – The
Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelperinstance this method extends. - expression (System.String) – Expression name, relative to the current model.
- message (System.String) – The message to be displayed. If <code>null</code> or empty, method extracts an error string from the
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionaryobject. Message will always be visible but client-side validation may update the associated CSS class. - htmlAttributes (System.Object) – An
System.Objectthat contains the HTML attributes for the (Microsoft.AspNetCore.Mvc.Rendering.ViewContext.ValidationMessageElement) element. Alternatively, anSystem.Collections.Generic.IDictionary`2instance containing the HTML attributes.
Return type: Returns: A new
Microsoft.AspNetCore.Html.IHtmlContentcontaining aMicrosoft.AspNetCore.Mvc.Rendering.ViewContext.ValidationMessageElementelement. <code>null</code> if the <em>expression</em> is valid and client-side validation is disabled.public static IHtmlContent ValidationMessage(this IHtmlHelper htmlHelper, string expression, string message, object htmlAttributes)
- htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper) – The
-
ValidationMessage(Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper, System.String, System.String, System.String) Returns the validation message if an error exists in the
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionaryobject for the specified <em>expression</em>.Arguments: - htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper) – The
Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelperinstance this method extends. - expression (System.String) – Expression name, relative to the current model.
- message (System.String) – The message to be displayed. If <code>null</code> or empty, method extracts an error string from the
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionaryobject. Message will always be visible but client-side validation may update the associated CSS class. - tag (System.String) – The tag to wrap the <em>message</em> in the generated HTML. Its default value is
Microsoft.AspNetCore.Mvc.Rendering.ViewContext.ValidationMessageElement.
Return type: Returns: A new
Microsoft.AspNetCore.Html.IHtmlContentcontaining a <em>tag</em> element. <code>null</code> if the <em>expression</em> is valid and client-side validation is disabled.public static IHtmlContent ValidationMessage(this IHtmlHelper htmlHelper, string expression, string message, string tag)
- htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper) – The
-
ValidationMessageFor<TModel, TResult>(Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<TModel>, System.Linq.Expressions.Expression<System.Func<TModel, TResult>>)¶ Returns the validation message if an error exists in the
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionaryobject for the specified <em>expression</em>.Arguments: - htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<TModel>) – The
Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelperinstance this method extends. - expression (System.Linq.Expressions.Expression<System.Func<TModel, TResult>>) – An expression to be evaluated against the current model.
Return type: Returns: A new
Microsoft.AspNetCore.Html.IHtmlContentcontaining aMicrosoft.AspNetCore.Mvc.Rendering.ViewContext.ValidationMessageElementelement. <code>null</code> if the <em>expression</em> is valid and client-side validation is disabled.public static IHtmlContent ValidationMessageFor<TModel, TResult>(this IHtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TResult>> expression)
- htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<TModel>) – The
-
ValidationMessageFor<TModel, TResult>(Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<TModel>, System.Linq.Expressions.Expression<System.Func<TModel, TResult>>, System.String) Returns the validation message if an error exists in the
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionaryobject for the specified <em>expression</em>.Arguments: - htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<TModel>) – The
Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelperinstance this method extends. - expression (System.Linq.Expressions.Expression<System.Func<TModel, TResult>>) – An expression to be evaluated against the current model.
- message (System.String) – The message to be displayed. If <code>null</code> or empty, method extracts an error string from the
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionaryobject. Message will always be visible but client-side validation may update the associated CSS class.
Return type: Returns: A new
Microsoft.AspNetCore.Html.IHtmlContentcontaining aMicrosoft.AspNetCore.Mvc.Rendering.ViewContext.ValidationMessageElementelement. <code>null</code> if the <em>expression</em> is valid and client-side validation is disabled.public static IHtmlContent ValidationMessageFor<TModel, TResult>(this IHtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TResult>> expression, string message)
- htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<TModel>) – The
-
ValidationMessageFor<TModel, TResult>(Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<TModel>, System.Linq.Expressions.Expression<System.Func<TModel, TResult>>, System.String, System.Object) Returns the validation message if an error exists in the
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionaryobject for the specified <em>expression</em>.Arguments: - htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<TModel>) – The
Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelperinstance this method extends. - expression (System.Linq.Expressions.Expression<System.Func<TModel, TResult>>) – An expression to be evaluated against the current model.
- message (System.String) – The message to be displayed. If <code>null</code> or empty, method extracts an error string from the
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionaryobject. Message will always be visible but client-side validation may update the associated CSS class. - htmlAttributes (System.Object) – An
System.Objectthat contains the HTML attributes for the (Microsoft.AspNetCore.Mvc.Rendering.ViewContext.ValidationMessageElement) element. Alternatively, anSystem.Collections.Generic.IDictionary`2instance containing the HTML attributes.
Return type: Returns: A new
Microsoft.AspNetCore.Html.IHtmlContentcontaining aMicrosoft.AspNetCore.Mvc.Rendering.ViewContext.ValidationMessageElementelement. <code>null</code> if the <em>expression</em> is valid and client-side validation is disabled.public static IHtmlContent ValidationMessageFor<TModel, TResult>(this IHtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TResult>> expression, string message, object htmlAttributes)
- htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<TModel>) – The
-
ValidationMessageFor<TModel, TResult>(Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<TModel>, System.Linq.Expressions.Expression<System.Func<TModel, TResult>>, System.String, System.String) Returns the validation message if an error exists in the
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionaryobject for the specified <em>expression</em>.Arguments: - htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<TModel>) – The
Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelperinstance this method extends. - expression (System.Linq.Expressions.Expression<System.Func<TModel, TResult>>) – An expression to be evaluated against the current model.
- message (System.String) – The message to be displayed. If <code>null</code> or empty, method extracts an error string from the
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionaryobject. Message will always be visible but client-side validation may update the associated CSS class. - tag (System.String) – The tag to wrap the <em>message</em> in the generated HTML. Its default value is
Microsoft.AspNetCore.Mvc.Rendering.ViewContext.ValidationMessageElement.
Return type: Returns: A new
Microsoft.AspNetCore.Html.IHtmlContentcontaining the <em>tag</em> element. <code>null</code> if the <em>expression</em> is valid and client-side validation is disabled.public static IHtmlContent ValidationMessageFor<TModel, TResult>(this IHtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TResult>> expression, string message, string tag)
- htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<TModel>) – The
-
ValidationSummary(Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper)¶ Returns an unordered list (<ul> element) of validation messages that are in the
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionaryobject.Arguments: htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper) – The Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelperinstance this method extends.Return type: Microsoft.AspNetCore.Html.IHtmlContent Returns: New Microsoft.AspNetCore.Html.IHtmlContentcontaining a <div> element wrapping the <ul> element.Microsoft.AspNetCore.Html.HtmlString.Emptyif the current model is valid and client-side validation is disabled).public static IHtmlContent ValidationSummary(this IHtmlHelper htmlHelper)
-
ValidationSummary(Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper, System.Boolean) Returns an unordered list (<ul> element) of validation messages that are in the
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionaryobject.Arguments: - htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper) – The
Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelperinstance this method extends. - excludePropertyErrors (System.Boolean) – If <code>true</code>, display model-level errors only; otherwise display all errors.
Return type: Returns: New
Microsoft.AspNetCore.Html.IHtmlContentcontaining a <div> element wrapping the <ul> element.Microsoft.AspNetCore.Html.HtmlString.Emptyif the current model is valid and client-side validation is disabled).public static IHtmlContent ValidationSummary(this IHtmlHelper htmlHelper, bool excludePropertyErrors)
- htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper) – The
-
ValidationSummary(Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper, System.Boolean, System.String) Returns an unordered list (<ul> element) of validation messages that are in the
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionaryobject.Arguments: - htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper) – The
Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelperinstance this method extends. - excludePropertyErrors (System.Boolean) – If <code>true</code>, display model-level errors only; otherwise display all errors.
- message (System.String) – The message to display with the validation summary.
Return type: Returns: New
Microsoft.AspNetCore.Html.IHtmlContentcontaining a <div> element wrapping theMicrosoft.AspNetCore.Mvc.Rendering.ViewContext.ValidationSummaryMessageElementelement (which, in turn, wraps the <em>message</em>) and the <ul> element.Microsoft.AspNetCore.Html.HtmlString.Emptyif the current model is valid and client-side validation is disabled).public static IHtmlContent ValidationSummary(this IHtmlHelper htmlHelper, bool excludePropertyErrors, string message)
- htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper) – The
-
ValidationSummary(Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper, System.Boolean, System.String, System.Object) Returns an unordered list (<ul> element) of validation messages that are in the
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionaryobject.Arguments: - htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper) – The
Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelperinstance this method extends. - excludePropertyErrors (System.Boolean) – If <code>true</code>, display model-level errors only; otherwise display all errors.
- message (System.String) – The message to display with the validation summary.
- htmlAttributes (System.Object) – An
System.Objectthat contains the HTML attributes for the topmost (<div>) element. Alternatively, anSystem.Collections.Generic.IDictionary`2instance containing the HTML attributes.
Return type: Returns: New
Microsoft.AspNetCore.Html.IHtmlContentcontaining a <div> element wrapping theMicrosoft.AspNetCore.Mvc.Rendering.ViewContext.ValidationSummaryMessageElementelement (which wraps the <em>message</em>) and the <ul> element.Microsoft.AspNetCore.Html.HtmlString.Emptyif the current model is valid and client-side validation is disabled).public static IHtmlContent ValidationSummary(this IHtmlHelper htmlHelper, bool excludePropertyErrors, string message, object htmlAttributes)
- htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper) – The
-
ValidationSummary(Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper, System.Boolean, System.String, System.String) Returns an unordered list (<ul> element) of validation messages that are in the
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionaryobject.Arguments: - htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper) – The
Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelperinstance this method extends. - excludePropertyErrors (System.Boolean) – If <code>true</code>, display model-level errors only; otherwise display all errors.
- message (System.String) – The message to display with the validation summary.
- tag (System.String) – The tag to wrap the <em>message</em> in the generated HTML. Its default value is
Microsoft.AspNetCore.Mvc.Rendering.ViewContext.ValidationSummaryMessageElement.
Return type: Returns: New
Microsoft.AspNetCore.Html.IHtmlContentcontaining a <div> element wrapping the <em>tag</em> element and the <ul> element.Microsoft.AspNetCore.Html.HtmlString.Emptyif the current model is valid and client-side validation is disabled).public static IHtmlContent ValidationSummary(this IHtmlHelper htmlHelper, bool excludePropertyErrors, string message, string tag)
- htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper) – The
-
ValidationSummary(Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper, System.String) Returns an unordered list (<ul> element) of validation messages that are in the
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionaryobject.Arguments: - htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper) – The
Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelperinstance this method extends. - message (System.String) – The message to display with the validation summary.
Return type: Returns: New
Microsoft.AspNetCore.Html.IHtmlContentcontaining a <div> element wrapping theMicrosoft.AspNetCore.Mvc.Rendering.ViewContext.ValidationSummaryMessageElementelement (which wraps the <em>message</em>) and the <ul> element.Microsoft.AspNetCore.Html.HtmlString.Emptyif the current model is valid and client-side validation is disabled).public static IHtmlContent ValidationSummary(this IHtmlHelper htmlHelper, string message)
- htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper) – The
-
ValidationSummary(Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper, System.String, System.Object) Returns an unordered list (<ul> element) of validation messages that are in the
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionaryobject.Arguments: - htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper) – The
Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelperinstance this method extends. - message (System.String) – The message to display with the validation summary.
- htmlAttributes (System.Object) – An
System.Objectthat contains the HTML attributes for the topmost (<div>) element. Alternatively, anSystem.Collections.Generic.IDictionary`2instance containing the HTML attributes.
Return type: Returns: New
Microsoft.AspNetCore.Html.IHtmlContentcontaining a <div> element wrapping theMicrosoft.AspNetCore.Mvc.Rendering.ViewContext.ValidationSummaryMessageElementelement (which wraps the <em>message</em>) and the <ul> element.Microsoft.AspNetCore.Html.HtmlString.Emptyif the current model is valid and client-side validation is disabled).public static IHtmlContent ValidationSummary(this IHtmlHelper htmlHelper, string message, object htmlAttributes)
- htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper) – The
-
ValidationSummary(Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper, System.String, System.Object, System.String) Returns an unordered list (<ul> element) of validation messages that are in the
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionaryobject.Arguments: - htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper) – The
Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelperinstance this method extends. - message (System.String) – The message to display with the validation summary.
- htmlAttributes (System.Object) – An
System.Objectthat contains the HTML attributes for the topmost (<div>) element. Alternatively, anSystem.Collections.Generic.IDictionary`2instance containing the HTML attributes. - tag (System.String) – The tag to wrap the <em>message</em> in the generated HTML. Its default value is
Microsoft.AspNetCore.Mvc.Rendering.ViewContext.ValidationSummaryMessageElement.
Return type: Returns: New
Microsoft.AspNetCore.Html.IHtmlContentcontaining a <div> element wrapping the <em>tag</em> element and the <ul> element.Microsoft.AspNetCore.Html.HtmlString.Emptyif the current model is valid and client-side validation is disabled).public static IHtmlContent ValidationSummary(this IHtmlHelper htmlHelper, string message, object htmlAttributes, string tag)
- htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper) – The
-
ValidationSummary(Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper, System.String, System.String) Returns an unordered list (<ul> element) of validation messages that are in the
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionaryobject.Arguments: - htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper) – The
Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelperinstance this method extends. - message (System.String) – The message to display with the validation summary.
- tag (System.String) – The tag to wrap the <em>message</em> in the generated HTML. Its default value is
Microsoft.AspNetCore.Mvc.Rendering.ViewContext.ValidationSummaryMessageElement.
Return type: Returns: New
Microsoft.AspNetCore.Html.IHtmlContentcontaining a <div> element wrapping the <em>tag</em> element and the <ul> element.Microsoft.AspNetCore.Html.HtmlString.Emptyif the current model is valid and client-side validation is disabled).public static IHtmlContent ValidationSummary(this IHtmlHelper htmlHelper, string message, string tag)
- htmlHelper (Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper) – The
-