栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

JsonResult在ASP.NET CORE 2.1中返回Json

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

JsonResult在ASP.NET CORE 2.1中返回Json

在asp.net-core-2.1

Controllerbase
中没有
Json(Object)
方法。但是
Controller
确实如此。

因此,要么将当前控制器重构为

Controller

public class GraficResourcesApiController : Controller {    //...}

可以访问该

Controller.Json
方法,或者您可以
JsonResult
在操作中初始化一个新的自己

return new JsonResult(rows);

这基本上是该方法在内部执行的操作

Controller

/// <summary>/// Creates a <see cref="JsonResult"/> object that serializes the specified <paramref name="data"/> object/// to JSON./// </summary>/// <param name="data">The object to serialize.</param>/// <returns>The created <see cref="JsonResult"/> that serializes the specified <paramref name="data"/>/// to JSON format for the response.</returns>[NonAction]public virtual JsonResult Json(object data){    return new JsonResult(data);}/// <summary>/// Creates a <see cref="JsonResult"/> object that serializes the specified <paramref name="data"/> object/// to JSON./// </summary>/// <param name="data">The object to serialize.</param>/// <param name="serializerSettings">The <see cref="JsonSerializerSettings"/> to be used by/// the formatter.</param>/// <returns>The created <see cref="JsonResult"/> that serializes the specified <paramref name="data"/>/// as JSON format for the response.</returns>/// <remarks>Callers should cache an instance of <see cref="JsonSerializerSettings"/> to avoid/// recreating cached data with each call.</remarks>[NonAction]public virtual JsonResult Json(object data, JsonSerializerSettings serializerSettings){    if (serializerSettings == null)    {        throw new ArgumentNullException(nameof(serializerSettings));    }    return new JsonResult(data, serializerSettings);}

资源



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/485533.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号