METHOD

TypedResults.ValidationProblem

Creates a concrete ValidationProblem result representing a 400 response with field-level errors. Constructing it does not execute the HTTP response; actual status, content type and serialization need integration tests. Requires ASP.NET Core.

Formal Syntax & Structure

csharp syntaxcsharp
TypedResults.ValidationProblem(errors)

Working Example

Example Snippetcsharp
using System;using System.IO;using System.Collections.Generic;using System.Net;using System.Net.Http;using System.Net.Http.Headers;using System.Threading;using Microsoft.AspNetCore.Http;var result = TypedResults.ValidationProblem(new Dictionary<string,string[]> { ["quantity"] = new[]{"Use 1 through 5."} });Console.WriteLine(result.ProblemDetails.Errors.Count); // 1
C# & .NET Reference