保存或者修改时给的提示,但是提示有点笼统 请各位看看 帮忙给个建议
VS2017
这个时控制器ajax SAVE保存方法
这个是js 保存方法
ef涉及到数据库里面太多异常需要告知用户是这样的。
public class HijackErrorFilterAttribute : ExceptionFilterAttribute, IExceptionFilter { static Exception GetInnerException(Exception ex) { return ex.InnerException == null ? ex : GetInnerException(ex.InnerException); } public void OnException(ExceptionContext filterContext) { string SpliteErrorText(string exceptionString) { var errorMsg = exceptionString; errorMsg = errorMsg.Length > 64 ? errorMsg.Substring(0, 64) : errorMsg; var index = errorMsg.IndexOf("。"); errorMsg = index > 0 ? errorMsg.Substring(0, index + 1) : errorMsg; errorMsg = errorMsg.ToISO_8859_1(); return errorMsg; } switch (filterContext.Exception) { case DbEntityValidationException ex: var errorContent = new StringBuilder(); foreach (var dbEntityValidationResult in ex.EntityValidationErrors) foreach (var error in dbEntityValidationResult.ValidationErrors) errorContent.Append(error.ErrorMessage); var errorMsg = errorContent.ToString(); Loger.Log.Info(errorMsg, filterContext.Exception); filterContext.Result = new HttpStatusCodeResult((HttpStatusCode)507, SpliteErrorText(errorMsg)); break; case InfoException ex: Loger.Log.Info(ex); filterContext.Result = new HttpStatusCodeResult((HttpStatusCode)506, SpliteErrorText(GetInnerException(filterContext.Exception).Message)); break; default: Loger.Log.Error(filterContext.Exception); filterContext.Result = new HttpStatusCodeResult(HttpStatusCode.InternalServerError, SpliteErrorText(filterContext.Exception.Message)); break; } filterContext.ExceptionHandled = true; } public override void OnException(HttpActionExecutedContext actionExecutedContext) { Loger.Log.Error(actionExecutedContext.Exception); base.OnException(actionExecutedContext); } }
提示里说了,让了查看inner exception 。调试,到达发生异常的那行代码时,查看inner exception
后台出错了,调试代码就知道详细错误了!
好的 谢谢
@傻傻的鱼: 出错地方,try{}catch{}查看详细错误!
封装的EF.然后在实体里加了属性验证?
这个后台提示还是debug追踪一下比较好看到问题所在...