Asp.net core mvc 在MVC6中,返回Json(rows,JsonRequestBehavior.AllowGet)问题

Asp.net core mvc 在MVC6中,返回Json(rows,JsonRequestBehavior.AllowGet)问题,asp.net-core-mvc,Asp.net Core Mvc,在MVC6中,返回Json(rows,JsonRequestBehavior.AllowGet);方法已更改,不允许设置JsonrequestBehavior。MVC6中的替代方案是,采用JsonRequestBehavior的Json方法的重载不再存在于aspnet核心中 您只需使用要发送回的对象数据调用Json方法即可 public IActionResult GetJsonData() { var rows = new List<string> { "Item 1","

在MVC6中,返回Json(rows,JsonRequestBehavior.AllowGet);方法已更改,不允许设置JsonrequestBehavior。MVC6

中的替代方案是,采用JsonRequestBehavior的
Json
方法的重载不再存在于aspnet核心中

您只需使用要发送回的对象数据调用
Json
方法即可

public IActionResult GetJsonData()
{
  var rows = new List<string>  {  "Item 1","Item 2" };
  return Json(rows);
}
并让内容谈判者以请求的格式返回数据(通过Accept标头)。ASP.NET核心MVC使用的默认格式是JSON。因此,如果您没有显式地请求另一种格式(例如:application/xml),您将得到json响应。

试试这个

public JsonResult GetJsonData()
{
  var data= //your list values
  return Json(data);
}
 [HttpGet]
    public JsonResult List()
    {          
        var settings = new JsonSerializerSettings();

        return Json(rows, settings);
    }
试试这个

public JsonResult GetJsonData()
{
  var data= //your list values
  return Json(data);
}
 [HttpGet]
    public JsonResult List()
    {          
        var settings = new JsonSerializerSettings();

        return Json(rows, settings);
    }

ASP.net core 1中不推荐使用JsonRequestBehavior。只需使用returnjson()

我正在从我的控制器重新运行json reuslt。它通过设置sonRequestBehavior.AllowGet与mvc4一起工作。在MVC6中,我无法设置此beahviour。。。