当前位置: 首页>>代码示例>>C#>>正文


C# JsonResult.ExecuteResult方法代码示例

本文整理汇总了C#中System.Web.Mvc.JsonResult.ExecuteResult方法的典型用法代码示例。如果您正苦于以下问题:C# JsonResult.ExecuteResult方法的具体用法?C# JsonResult.ExecuteResult怎么用?C# JsonResult.ExecuteResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.Mvc.JsonResult的用法示例。


在下文中一共展示了JsonResult.ExecuteResult方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Application_Error

        protected void Application_Error()
        {
            var httpContext = HttpContext.Current;
            if (httpContext == null) return;

            var context = new HttpContextWrapper(System.Web.HttpContext.Current);
            var routeData = RouteTable.Routes.GetRouteData(context);

            var requestContext = new RequestContext(context, routeData);
            /* when the request is ajax the system can automatically handle a mistake with a JSON response. then overwrites the default response */
            if (requestContext.HttpContext.Request.IsAjaxRequest())
            {
                httpContext.Response.Clear();
                var controllerName = requestContext.RouteData.GetRequiredString("controller");
                var factory = ControllerBuilder.Current.GetControllerFactory();
                var controller = factory.CreateController(requestContext, controllerName);
                var controllerContext = new ControllerContext(requestContext, (ControllerBase)controller);

                var jsonResult = new JsonResult
                {
                    Data = new {success = false, serverError = "500"},
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                };
                jsonResult.ExecuteResult(controllerContext);
                httpContext.Response.End();
            }
            else
            {
                httpContext.Response.Redirect("~/Error");
            }
        }
开发者ID:itverket,项目名称:geek-retreat,代码行数:31,代码来源:Global.asax.cs

示例2: OnException

        public override void OnException(ExceptionContext exceptionContext)
        {
            base.OnException(exceptionContext);

            logError(exceptionContext);

            // inform elmah
            var httpContext = exceptionContext.HttpContext.ApplicationInstance.Context;
            var signal = ErrorSignal.FromContext(httpContext);
            signal.Raise(exceptionContext.Exception, httpContext);

            // change the result if an ajax request
            var request = exceptionContext.HttpContext.Request;
            if (request.IsAjaxRequest() == false)
                return;

            var jsonDto = new Harbor.UI.Models.InternalServerErrorDto
                {
                    exception = exceptionContext.Exception.Message,
                    exceptionType = exceptionContext.Exception.GetType().FullName
                };
            #if DEBUG
            jsonDto.stackTrace = exceptionContext.Exception.StackTrace;
            #endif
            var jsonResult = new JsonResult {Data = jsonDto, JsonRequestBehavior = JsonRequestBehavior.AllowGet};
            exceptionContext.HttpContext.Response.Clear();
            exceptionContext.Result = jsonResult;
            //exceptionContext.HttpContext.Response.StatusCode = 500;
            exceptionContext.ExceptionHandled = true;
            jsonResult.ExecuteResult(exceptionContext);
            exceptionContext.HttpContext.Response.End();
        }
开发者ID:jhorback,项目名称:Harbor,代码行数:32,代码来源:ServerErrorExceptionFilterAttribute.cs

示例3: OnException

 protected override void OnException(ExceptionContext filterContext)
 {
     if (filterContext.HttpContext.IsCustomErrorEnabled || true)  //IsCustomErrorEnabled always false if client is localhost or client and server IPs identical. True set to override.
     {
         filterContext.ExceptionHandled = true;
         // If this is an ajax request, return the exception in the response            
         if (filterContext.HttpContext.Request.IsAjaxRequest())
         {
             //if (HttpContext.Response.ContentType == "text/html")
             //{
             //    filterContext.HttpContext.Response.StatusCode = 500;
             //    var json = new JsonResult();
             //    json.JsonRequestBehavior = JsonRequestBehavior.AllowGet;   //SICHERHEITSPROBLEM: s. http://haacked.com/archive/2009/06/25/json-hijacking.aspx
             //    json.Data = HttpUtility.UrlEncode(filterContext.Exception.Message); // +filterContext.Exception.StackTrace;
             //    json.ExecuteResult(this.ControllerContext);
             //}
             //else
             //{
                 filterContext.HttpContext.Response.StatusCode = 500;
                 var json = new JsonResult();
                 json.JsonRequestBehavior = JsonRequestBehavior.AllowGet;   //SICHERHEITSPROBLEM: s. http://haacked.com/archive/2009/06/25/json-hijacking.aspx
                 json.Data = HttpUtility.UrlEncode(filterContext.Exception.Message); // +filterContext.Exception.StackTrace;
                 json.ExecuteResult(this.ControllerContext);
             //}
         }
         else
         {
             ViewData.Model = new System.Web.Mvc.HandleErrorInfo(filterContext.Exception, "ControllerName", "ActionName");
             // Pass a flag to the view to tell it whether or not to show a the stack trace                
             ViewBag.IsCustomErrorEnabled = true; //filterContext.HttpContext.IsCustomErrorEnabled;
             this.View("Error").ExecuteResult(this.ControllerContext);
         }
     }
 }
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:34,代码来源:BaseController.cs

示例4: Execute

        public override void Execute(object model, ControllerContext context)
        {
            context.HttpContext = new HttpContextWrapper(HttpContext.Current);
            var result = new JsonResult {Data = model};

            result.ExecuteResult(context);
        }
开发者ID:rexwhitten,项目名称:Siege,代码行数:7,代码来源:JsonResponse.cs

示例5: ExecuteResult

        public override void ExecuteResult(ControllerContext context)
        {
            JsonResult result = new JsonResult();

            result.Data = GetResult(context);

            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            result.ExecuteResult(context);
        }
开发者ID:ielkanyuk,项目名称:BiBiHelp,代码行数:9,代码来源:AjaxResult.cs

示例6: RenderAjaxView

        protected virtual void RenderAjaxView(HttpRequestBase request, Exception currentError)
        {
            var jsonResult = new JsonResult
                             {
                                 JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                                 Data = new {error_message = GetJsonErrorMessage(request, currentError)}
                             };

            jsonResult.ExecuteResult(NewControllerContext(request));
        }
开发者ID:alanstevens,项目名称:Contrive,代码行数:10,代码来源:ErrorViewRendererBase.cs

示例7: ExecuteResult

        public override void ExecuteResult(ControllerContext context)
        {
            var result = new JsonResult
            {
                Data = Data,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };

            result.ExecuteResult(context);
        }
开发者ID:Wipcore,项目名称:Ecommerce,代码行数:10,代码来源:AjaxFormResult.cs

示例8: ExecuteResult

        public override void ExecuteResult(ControllerContext context)
        {
            var jsonResponse = new JsonResult
            {
                Data = this,
                ContentType = "application/json",
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };

            jsonResponse.ExecuteResult(context);
        }
开发者ID:jesusmoreno85,项目名称:LoginTestApp,代码行数:11,代码来源:GenericStateResult.cs

示例9: ExecuteResult

 public override void ExecuteResult(ControllerContext context)
 {
     var response = new JsonResponse
                        {
                            FatalErrorUrl = _fatalErrorUrl,
                            ValidationErrorMessage = _validationErrorMessage,
                            Data = _data, Success = string.IsNullOrWhiteSpace(_validationErrorMessage)
                        };
     var json = new JsonResult
     {
         Data = response,
         JsonRequestBehavior = JsonRequestBehavior.AllowGet
     };
     json.ExecuteResult(context);
 }
开发者ID:OndeVai,项目名称:Shared---Common-code-for-.net-and-MVC-3,代码行数:15,代码来源:CustomJsonResult.cs

示例10: OnException

 public override void OnException(ExceptionContext context)
 {
     if (IsAjaxCall)
     {
         context.ExceptionHandled = true;
         var jsonResult = new JsonResult();
         jsonResult.Data = new {Message = context.Exception.Message , MessageType = "Error"};
         jsonResult.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
         jsonResult.ExecuteResult(context);
     }
     else
     {
         // if not an ajax request, continue with logic implemented by MVC -> html error page
         base.OnException(context);
     }
 }
开发者ID:squadwuschel,项目名称:MvcControllerToProxyGenerator,代码行数:16,代码来源:CustomErrorHandlerAttribute.cs

示例11: ExecuteResult

        public override void ExecuteResult(ControllerContext context)
        {
            if (context.RequestContext.HttpContext.Request.IsAjaxRequest())
            {
                string destinationUrl = UrlHelper.GenerateContentUrl(Url, context.HttpContext);

                JsonResult result = new JsonResult()
                {
                    Data = new{LoggedOut=true,RedirectUrl = destinationUrl},
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                };
                result.ExecuteResult(context);
            }
            else
                base.ExecuteResult(context);
        }
开发者ID:reharik,项目名称:MethodFitness,代码行数:16,代码来源:DCIController.cs

示例12: ExecuteResult

 public override void ExecuteResult(ControllerContext context)
 {
     var contentType = context.RequestContext.HttpContext.Request.Headers["Accept"];
     if (contentType != null && contentType.Contains("application/json"))
     {
         if (Model is IEnumerable && !(Model is string))
         {
             Model = new CollectionWrapper { Collection = (IEnumerable)Model };
         }
         var result = new JsonResult { Data = Model, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
         result.ExecuteResult(context);
     }
     else
     {
         context.Controller.ViewData.Model = Model;
         var result = new ViewResult { ViewData = context.Controller.ViewData };
         result.ExecuteResult(context);
     }
 }
开发者ID:basicdays,项目名称:Guidelines,代码行数:19,代码来源:DynamicView.cs

示例13: ExecuteResult

 public override void ExecuteResult(ControllerContext context)
 {
     var cr = new ContentResult();
     if (Mode == RenderMode.Html)
     {
         cr.ContentType = "text/html";
         cr.Content = mHTML;
     }
     else if (Mode == RenderMode.Text)
     {
         cr.ContentType = "text/plain";
         cr.Content = mText;
     }
     else if (Mode == RenderMode.Json)
     {
         JsonResult jr = new JsonResult();
         jr.Data = new
         {
             mMessage.From,
             mMessage.To,
             mMessage.CC,
             mMessage.Bcc,
             mMessage.Headers,
             mMessage.Priority,
             mMessage.ReplyToList,
             mMessage.Sender,
             mMessage.Subject,
             mMessage.SubjectEncoding
         };
         jr.ExecuteResult(context);
         return;
     }
     else
     {
         new SmtpClient().Send(mMessage);
         if (Mode == RenderMode.SendWithJson)
         {
             var jr = new JsonResult();
             jr.Data = new { success = true };
             jr.ExecuteResult(context);
             return;
         }
         cr.Content = "OK";
     }
     cr.ExecuteResult(context);
 }
开发者ID:djMax,项目名称:AlienForce,代码行数:46,代码来源:EmailResult.cs

示例14: RenderAjaxView

        private static void RenderAjaxView(HttpApplication httpApplication, HttpStatusCode httpStatusCode,
                                             Exception currentError)
        {
            // Ok. lets check if this content type contains a request for json.
            string errorMessage = httpApplication.Request.ContentType.Contains("json")
                                       ? currentError.Message
                                       : string.Format(
                                           "An error occured but we are unable to handle the request.ContentType [{0}]. Anyways, the error is: {1}",
                                           httpApplication.Request.ContentType,
                                           currentError.Message);
            

            var errorController = new FakeErrorController();
            var controllerContext =
                new ControllerContext(httpApplication.Context.Request.RequestContext, errorController);
            var jsonResult = new JsonResult
            {
                JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                Data = new
                {
                    error_message = errorMessage
                }
            };
            jsonResult.ExecuteResult(controllerContext);

            // Lets make sure we set the correct Error Status code :)
            httpApplication.Response.StatusCode = (int) httpStatusCode;
        }
开发者ID:sdanna,项目名称:WorldDomination.Web.Mvc.ErrorHandling,代码行数:28,代码来源:CustomErrorHandlingModule.cs

示例15: ExecuteResult

        /// <summary>
        /// 执行
        /// </summary>
        /// <param name="context"></param>
        public override void ExecuteResult(ControllerContext context)
        {
            var model = new
            {
                status = Status,
                message = Message,
                data = Data,
                url = Url
            };

            var result = new JsonResult
            {
                Data = model,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                MaxJsonLength = 104857600  //100MB
            };

            result.ExecuteResult(context);
        }
开发者ID:qinfengwangyi,项目名称:Qin.Blog,代码行数:23,代码来源:ActionReturn.cs


注:本文中的System.Web.Mvc.JsonResult.ExecuteResult方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。