示例#1
0
        /// <summary>
        /// 覆盖 JsonResult 的方法;
        /// </summary>
        /// <param name="context"></param>
        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            HttpResponseBase response = context.HttpContext.Response;

            if (!string.IsNullOrEmpty(this.ContentType))
            {
                response.ContentType = this.ContentType;
            }
            else
            {
                response.ContentType = "application/json";
            }
            var data = this.GetJsonResultValue();

            if (data != null)
            {
                IsoDateTimeConverter timeConvert = new IsoDateTimeConverter();
                timeConvert.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
                string content = "";
                if (data is SerializeToJson)
                {
                    content = ((SerializeToJson)data).SerializeToJson();
                }
                else
                {
                    content = JsonConvert.SerializeObject(content, Newtonsoft.Json.Formatting.None, timeConvert);
                }
                response.Write(content);
            }
        }
示例#2
0
 public static void Write(this HttpResponse response, string data)
 {
     byte[] bytes = System.Text.Encoding.UTF8.GetBytes(data);
     response.Write(bytes);;
 }