Пример #1
0
        private static ActionResult GetValidationException(ExceptionContext exceptionContext
                                                           , bool isAjaxRequest)
        {
            ActionResult result;
            var          msg = string.Format(
                @"<b>验证失败:  </b><span style='color:Red;'>{0}</span>", exceptionContext.Exception.Message);

            if (isAjaxRequest)
            {
                result = new FormatJsonResult()
                {
                    Data = new ResponseData
                    {
                        success = false,
                        msg     = msg
                    }.Info()
                };
            }
            else
            {
                result = new ContentResult()
                {
                    Content = msg
                };
            }

            return(result);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="modelState"></param>
        /// <returns></returns>
        public static FormatJsonResult ToJsonResult(this ModelStateDictionary modelState)
        {
            string msg = string.Empty;
            foreach (var item in modelState)
            {
                foreach (var e in item.Value.Errors)
                {
                    msg += e.ErrorMessage;
                }
            }
            var result = new FormatJsonResult()
            {
                Data = new ResponseData { msg = msg, success = false }.Warning()
            };

            return result;
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="modelState"></param>
        /// <returns></returns>
        public static FormatJsonResult ToJsonResult(this ModelStateDictionary modelState)
        {
            string msg = string.Empty;

            foreach (var item in modelState)
            {
                foreach (var e in item.Value.Errors)
                {
                    msg += e.ErrorMessage;
                }
            }
            var result = new FormatJsonResult()
            {
                Data = new ResponseData {
                    msg = msg, success = false
                }.Warning()
            };

            return(result);
        }
        private static ActionResult GetValidationException(ExceptionContext exceptionContext
            , bool isAjaxRequest)
        {
            ActionResult result;
            var msg = string.Format(
            @"<b>验证失败:  </b><span style='color:Red;'>{0}</span>", exceptionContext.Exception.Message);
            if (isAjaxRequest)
            {
                result = new FormatJsonResult()
                {
                    Data = new ResponseData
                    {
                        success = false,
                        msg = msg
                    }.Info()
                };
            }
            else
            {
                result = new ContentResult()
                {
                    Content = msg
                };
            }

            return result;
        }