예제 #1
0
        /// <summary>
        /// Return a JsonResult containing an error response
        /// </summary>
        /// <param name="messages">Messages object the client will use to inform the user of the errors and any actions that can be taken</param>
        /// <param name="resultsData">Any state data relevant to the operation</param>
        protected static JsonResult JsonError(ModelStateDictionary messages, object resultsData = null)
        {
            //stops only content/html error with the line "Bad Request" being returned.
            //Response.TrySkipIisCustomErrors = true;      //now set the web.config httpError to passthrough
            if (System.Web.HttpContext.Current != null)
            {
                System.Web.HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.BadRequest;
            }

            var data = JsonResponse.ErrorResponse(messages.CustomSerialiseErrors(), resultsData);

            return(new JsonResult()
            {
                Data = data,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }