// Copyright (c) Microsoft Open Technologies, Inc. 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.AspNet.Mvc;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.WebUtilities;
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([NotNull] ModelStateDictionary modelState, bool includeErrorDetail)
: base(new HttpError(modelState, includeErrorDetail))
{
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 async Task ExecuteResultAsync(ActionContext context)
{
context.HttpContext.Response.StatusCode = StatusCodes.Status400BadRequest;
await base.ExecuteResultAsync(context);
}
}
}