This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using Microsoft.AspNetCore.Mvc; | |
namespace WebApplication.Controllers | |
{ | |
[ApiController] | |
[Route("[controller]")] | |
public class DemoController : ControllerBase | |
{ | |
[HttpPost] | |
public ActionResult Post() | |
{ | |
var problemDetails = new ProblemDetails | |
{ | |
Detail = "The request parameters failed to validate.", | |
Instance = null, | |
Status = 400, | |
Title = "Validation Error", | |
Type = "https://example.net/validation-error", | |
}; | |
problemDetails.Extensions.Add("invalidParams", new List<ValidationProblemDetailsParam>() | |
{ | |
new("name", "Cannot be blank."), | |
new("age", "Must be great or equals to 18.") | |
}); | |
return new ObjectResult(problemDetails) | |
{ | |
StatusCode = 400 | |
}; | |
} | |
} | |
public class ValidationProblemDetailsParam | |
{ | |
public ValidationProblemDetailsParam(string name, string reason) | |
{ | |
Name = name; | |
Reason = reason; | |
} | |
public string Name { get; set; } | |
public string Reason { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment