-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed as not planned
Closed as not planned
Copy link
Description
Is there an existing issue for this?
- I have searched the existing issues
test.zip
Describe the bug
[EmailAddress] DataAnnotations not work correctly with user@example without .com
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc;
namespace test.Controllers;
[ApiController]
[Route("[controller]/[action]")]
public class WeatherForecastController : ControllerBase
{
[HttpPost]
public IActionResult GetAll([FromBody] MyViewModel myViewModel)
{
if (ModelState.IsValid)
return Ok("Valid");
else return Ok("Not Valid");
}
}
public class MyViewModel
{
public int Id { get; set; }
[EmailAddress]
public required string Email { get; set; }
}
Expected Behavior
When we send this json on the body with swagger:
{ "id": 1, "email": "user@example" }
The GetAll() action method have to return "Not Valid"
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
7.0.201
Anything else?
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>
</Project>