private void OnError(ActionExecutedContext filterContext) { string htmlMsg = @"<script type='text/javascript'>alert('系统出错了');</script>"; var request = filterContext.RequestContext.HttpContext.Request; var result = new ContentResult { Content = htmlMsg, ContentType = "text/html", }; if (request.IsAjaxRequest()) { //filterContext.Result = new RedirectResult("/login"); filterContext.Result = new JsonResult { Data = new { ret = -998 }, ContentEncoding = System.Text.Encoding.UTF8, ContentType = "application/json", JsonRequestBehavior = JsonRequestBehavior.AllowGet }; } else filterContext.Result = result; }