码迷,mamicode.com
首页 > 移动开发 > 详细

abp 指定 AppService中某个方法不是用驼峰命名(CamelCase)返回

时间:2019-09-23 15:34:14      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:object   data   rac   返回   ted   json   convert   result   void   

一.直接使用ContentResult

 return new ContentResult
            {
                ContentType = "application/json",
                Content = JsonConvert.SerializeObject(obj,
                    new JsonSerializerSettings { ContractResolver = new DefaultContractResolver() })
            };

二 使用MVC ResultFilter

 public class JsonSerializeFilter : IResultFilter
    {
        public void OnResultExecuted(ResultExecutedContext context)
        {

        }

        public void OnResultExecuting(ResultExecutingContext context)
        {
            var result = context.Result as ObjectResult;
            context.Result = new ObjectResult(JsonConvert.SerializeObject(
                result?.Value,
                new JsonSerializerSettings { ContractResolver = new DefaultContractResolver() }
            ));
        }
    }
//使用

  [TypeFilter(typeof(JsonSerializeFilter))]
public async Task<DataTable> Linkdata(string t, string f, string q = "")
         {//todo
         }

abp 指定 AppService中某个方法不是用驼峰命名(CamelCase)返回

标签:object   data   rac   返回   ted   json   convert   result   void   

原文地址:https://www.cnblogs.com/hongshao/p/11572231.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!