Пример #1
0
        /// <summary>
        /// Coverts the data to JSON.
        /// </summary>
        /// <param name="context">The MVC controller context.</param>
        public override void ExecuteResult(ControllerContext context)
        {
            context.CatchNullArgument("context");

            HttpResponseBase response = context.HttpContext.Response;

            response.ContentType = !string.IsNullOrEmpty(this.ContentType) ? this.ContentType : "application/json";

            if (this.ContentEncoding != null)
            {
                response.ContentEncoding = this.ContentEncoding;
            }

            if (this.Data != null)
            {
                JsonTextWriter writer = new JsonTextWriter(response.Output)
                {
                    Formatting = this.Formatting
                };

                JsonSerializer serializer = JsonSerializer.Create(this.SerializerSettings);
                serializer.Serialize(writer, this.Data);

                writer.Flush();
            }
        }
Пример #2
0
        /// <summary>
        /// Coverts the data to JSON.
        /// </summary>
        /// <param name="context">The MVC controller context.</param>
        public override void ExecuteResult(ControllerContext context)
        {
            context.CatchNullArgument("context");

            HttpResponseBase response = context.HttpContext.Response;
            response.ContentType = !string.IsNullOrEmpty(this.ContentType) ? this.ContentType : "application/json";

            if (this.ContentEncoding != null)
            {
                response.ContentEncoding = this.ContentEncoding;
            }

            if (this.Data != null)
            {
                JsonTextWriter writer = new JsonTextWriter(response.Output) { Formatting = this.Formatting };

                JsonSerializer serializer = JsonSerializer.Create(this.SerializerSettings);
                serializer.Serialize(writer, this.Data);

                writer.Flush();
            }
        }