// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;
namespace System.Web.Http
{
///
/// An action result that returns a response and performs
/// content negotiation on an based on a .
///
public class InvalidModelStateResult : ObjectResult
{
/// Initializes a new instance of the class.
/// The model state to include in the error.
///
/// if the error should include exception messages; otherwise, .
///
public InvalidModelStateResult(ModelStateDictionary modelState, bool includeErrorDetail)
: base(new HttpError(modelState, includeErrorDetail))
{
if (modelState == null)
{
throw new ArgumentNullException(nameof(modelState));
}
ModelState = modelState;
IncludeErrorDetail = includeErrorDetail;
}
///
/// Gets the model state to include in the error.
///
public ModelStateDictionary ModelState { get; private set; }
///
/// Gets a value indicating whether the error should include exception messages.
///
public bool IncludeErrorDetail { get; private set; }
///
public override Task ExecuteResultAsync(ActionContext context)
{
context.HttpContext.Response.StatusCode = StatusCodes.Status400BadRequest;
return base.ExecuteResultAsync(context);
}
}
}