Skip to content

Is HTML5-validation supported? #20717

Closed as not planned
Closed as not planned
@pekspro

Description

@pekspro

In the documentation it says for the input tag helper:

Generates HTML5 validation attributes from data annotation attributes applied to model properties.

But if I have an property like this:

[Required]
[StringLength(10, MinimumLength = 5)]
[Display(Name = "Computer name")]
public string ComputerName { get; set; }

And then uses the input tag like this:

<input asp-for="ComputerName" class="form-control" />

It becomes generated like this:

<input class="form-control" type="text" data-val="true" 
data-val-length="The field Computer name must be a string with a minimum length of 5 and a maximum length of 10." 
data-val-length-max="10" data-val-length-min="5" 
data-val-required="The Computer name field is required." id="ComputerName" 
maxlength="10" name="ComputerName" value="">

There is no minlength and required attribute as expected. Also, the form tag is generated with the novalidate attribute which to my understanding disables HTML5 validation.

I’ve also tried to disable client-side validation. This removes the novalidate attribute on the form tag, but the minlength and required attribues is still missing.

To summary, is HTML5 validation supported as it mentioned in the documentation?

Issue 8573 is a bit related to this.

I’m asking only by curiosity :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    affected-very-fewThis issue impacts very few customersarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesenhancementThis issue represents an ask for new feature or an enhancement to an existing onefeature-mvc-razor-viewsFeatures related to the Razor view engine for Razor pages and MVC viewsseverity-majorThis label is used by an internal tool

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions