System.Web.Mvc.JsonpResult.ExecuteResult C# (CSharp) Method

ExecuteResult() public method

public ExecuteResult ( ControllerContext context ) : void
context ControllerContext
return void
        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null) {
                throw new ArgumentNullException("context");
            }

            this.JsonCallback = context.HttpContext.Request["jsoncallback"];

            if (string.IsNullOrEmpty(this.JsonCallback))
                this.JsonCallback = context.HttpContext.Request["callback"];

            if (string.IsNullOrEmpty(this.JsonCallback))
                throw new ArgumentNullException("JsonCallback required for JSONP response.");

            HttpResponseBase response = context.HttpContext.Response;

            if (!String.IsNullOrEmpty(ContentType)) {
                response.ContentType = ContentType;
            } else {
                response.ContentType = "application/json";
            }
            if (ContentEncoding != null) {
                response.ContentEncoding = ContentEncoding;
            }
            if (Data != null) {
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                response.Write(string.Format("{0}({1});", this.JsonCallback, serializer.Serialize(Data)));
            }
        }

Usage Example

 public static JsonpResult Jsonp(this Controller controller, object data)
 {
     JsonpResult result = new JsonpResult();
     result.Data = data;
     result.ExecuteResult(controller.ControllerContext);
     return result;
 }
All Usage Examples Of System.Web.Mvc.JsonpResult::ExecuteResult