Answer the question
In order to leave comments, you need to log in
How to change the format of generated model validation errors in ASP.NET Core Web API?
There is a class. If you do not transfer some of the properties in JSON on the client side, then an error is returned to the client. Is there any way to change the format of this error? I just return errors in one format, which I wrote myself and process on the client, but the validation error is in a different format, and because of this, this error is not processed on the client. You can check the type on the client, but it’s reluctant to add all this there, it’s easier on the server to bring it to a single view once.
Where to look? What can be done?
//
public class AddUserModel
{
[Required]
[MaxLength(Domain.Entities.Restriction.User.USER_NAME_MAX_LENGTH)]
[JsonProperty("userName", Required = Required.Always)]
public string UserName { get; set; }
[Required]
[JsonProperty("email", Required = Required.Always)]
public string Email { get; set; }
[Required]
[JsonProperty("phoneNumber", Required = Required.AllowNull)]
public string PhoneNumber { get; set; }
}
//
[HttpPost]
[Route("add-user")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status409Conflict)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
[Authorize(Roles = nameof(Role.Types.Administrator))]
public async Task<IActionResult> AddUser([FromBody] AddUserModel newUser)
{
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question