dotnet / dotnet/aspnetcore

Model client validation css styles not work well with @Html.EditorFor

Open
#30,799 3 comments 0 reactions 0 assignees View on GitHub
area-mvc feature-mvc-razor-views investigate
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Describe the bug

If use `@Html.EditorFor` with the expression for a property, client-side validation will display error message with wrong css style.

![image](https://user-images.githubusercontent.com/68624043/110598591-e58d2780-81bc-11eb-8ad7-0c17ac169278.png)

***The `class` attribute has no value***

![image](https://user-images.githubusercontent.com/68624043/110598650-f3db4380-81bc-11eb-9e3a-55d8aa7325d0.png)

### To Reproduce

```
@for (var i = 0; i < Model.TestChildModels.Count; i++)
{
@Html.EditorFor(model => model.TestChildModels[i])
}
```

_**_EditorTemplate/TestChildModel.cshtml_**_

```
@model TestChildModel















```
**The workaround I am using now**

_add following code snippet in `site.css`_

```
span.field-validation-error span {
color: red;
}
```

### Further technical details
- ASP.NET Core version 5.0

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.