Я пытаюсь использовать AS PNET CORE MVC 3.1 встроенную проверку, и что-то очень странное. По какой-то причине имена полей, которые содержат ошибки, идут со знаком «$». Кто-нибудь знает причину этого изменения с AS PNET CORE 2.2 на 3.1?
Я отправляю шаблон с недопустимой датой и замечаю, что возвращение поля dateOfBird идет с "$ «. префикс, как решить эту проблему и по какой причине этот префикс существует?
{
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"traceId": "|125b177f-444ca33308cefc01.",
"errors": {
"$.dateOfBirth": [
"The JSON value could not be converted to System.Nullable`1[System.DateTime]. Path: $.dateOfBirth | LineNumber: 6 | BytePositionInLine: 22."
]
}
}
My Startup.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace WebApplication5
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}
My Controller.cs (с внутренним классом ApplicationUser)
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
public class ApplicationUser
{
public string FirstName { get; set; }
public string LastName { get; set; }
public long FacebookId { get; set; }
public string PictureUrl { get; set; }
public DateTime? DateOfBirth { get; set; }
}
[HttpPost]
public bool Post([FromBody] ApplicationUser user)
{
return true;
}
}