-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Open
Milestone
Description
Description
System.ComponentModel.DataAnnotations.CompareAttribute genrates wrong error message.
Because it don't referes DisplayName property of DisplayNameAttribute but Name property of DisplayAttribute.
Reproduction Steps
- Create new ASP.NET Core Web App Project On Visual Studio 2022 (17.8)
- Add new Razor Page named "test" into pages folder.
- code below in test.cshtml.cs
public class testModel : PageModel
{
[BindProperty]
[DisplayName("Parent's mail address")]
[Display(Name = "xxxxx")]
public string? email { get; set; }
[BindProperty]
[DisplayName("Confirm mail address")]
[Compare(nameof(email), ErrorMessage = "Don't match with {1}")]
public string? confirmEmail { get; set; }
public void OnPost()
{
if (!ModelState.IsValid)
{
return;
}
}
}
4.code below in test.cshtml
<form method="post">
<input asp-for="email" />
<input asp-for="confirmEmail" />
<span asp-validation-for="confirmEmail"></span>
<input type="submit" />
</form>
- Run project and go to /test
- input "a" in first textbox, "b" in second textbox and click submit.
Expected behavior
It shows "Don't match with Parent's mail address" as error message.
Actual behavior
It shows "Don't match with xxxxx" as error message.
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response