Skip to content

Blazor Form Validation showing incorrect Display Name Annotation #11414

@pelhamrj

Description

@pelhamrj

Describe the bug

When using data annotations on a model with the <EditForm> component, DateTime does not display the correct [Display] name set on the annotated model.

To Reproduce

Steps to reproduce the behavior:

  1. Using this version of ASP.NET Core 3.0 Preview 6
  2. Create an empty project and use the following code:
public class MyModel {
    [Required]
    [Display(Name = "Received Date")]
    public DateTime ReceivedDate { get; set; }
}
<EditForm Model="@MyModel" OnValidSubmit="@HandleValidSubmit">
    <div class="input-group mb-3">
        <div class="input-group-prepend">
            <span class="input-group-text" id="Date Received">Date Received</span>
         </div>
         <InputDate Class="form-control" Id="DateReceived" @bind-Value="@MyModel.ReceivedDate" />
          <div class="invalid-feedback d-block">
              <ValidationMessage For="@(() => MyModel.ReceivedDate)" />
          </div>
    </div>
</EditForm>

Expected behavior

The error message should display "The Received Date field must be a date."

Actual behavior

The error message displays: "The ReceivedDate field must be a date." (Notice the lack of space on the field name).

Workaround

You can manually set the ParsingErrorMessage attribute as shown here:

<InputDate ParsingErrorMessage="The Received Date field must be a valid date." Class="form-control" Id="DateReceived" @bind-Value="@MyModel.ReceivedDate" />

Screenshots

image

image

image

Additional context

.NET Core SDK (reflecting any global.json):
 Version:   3.0.100-preview6-012264
 Commit:    be3f0c1a03

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17763
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.0.100-preview6-012264\

Host (useful for support):
  Version: 3.0.0-preview6-27804-01
  Commit:  fdf81c6faf

.NET Core SDKs installed:
  2.1.604 [C:\Program Files\dotnet\sdk]
  2.1.700-preview-009618 [C:\Program Files\dotnet\sdk]
  2.1.800-preview-009677 [C:\Program Files\dotnet\sdk]
  2.1.800-preview-009696 [C:\Program Files\dotnet\sdk]
  3.0.100-preview6-012264 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0-preview6.19307.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0-preview6-27804-01 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.0.0-preview6-27804-01 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.help wantedUp for grabs. We would accept a PR to help resolve this issue

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions