标签:vcsa space methods empty mvc odi .net object ext
直接贴代码了:
using System; using System.Web.Mvc; using Newtonsoft.Json; namespace MvcSample.Extensions { public class ConverterJsonResult : JsonResult { #region Fields private readonly JsonConverter[] _converters; #endregion #region Ctor public ConverterJsonResult(params JsonConverter[] converters) { _converters = converters; } #endregion #region Methods public override void ExecuteResult(ControllerContext context) { if (context == null) throw new ArgumentNullException("context"); if (context.HttpContext == null || context.HttpContext.Response == null) return; context.HttpContext.Response.ContentType = !string.IsNullOrEmpty(ContentType) ? ContentType : "application/json"; if (ContentEncoding != null) context.HttpContext.Response.ContentEncoding = ContentEncoding; if (Data != null) context.HttpContext.Response.Write(JsonConvert.SerializeObject(Data, _converters)); } #endregion } }
谢谢浏览!
ASP.NET MVC 下自定义 JsonResult,使用 Json.NET 序列化 JSON
标签:vcsa space methods empty mvc odi .net object ext
原文地址:https://www.cnblogs.com/Music/p/custom-json-result-in-asp-net-mvc.html