C# 无法识别Json类型

C# 无法识别Json类型,c#,asp.net-mvc,asp.net-web-api,C#,Asp.net Mvc,Asp.net Web Api,为什么我不能返回Json。它带有下划线,在当前上下文中不存在 using System; using System.Collections.Generic; using System.Net; using System.Net.Http; using System.Text; using System.Threading.Tasks; using System.Web.Http; using System.Web.Http.Results; using System.Web.Mvc; //cl

为什么我不能返回Json。它带有下划线,在当前上下文中不存在

using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Results;
using System.Web.Mvc;

//class and namespace detail removed to keep this post short

    public async Task<IHttpActionResult> Post(string url, StringContent data, Dictionary<string, string> headers)
    {
        using (var client = new HttpClient())
        {
                var response = await client.PostAsync(url, data);
                var result = await response.Content.ReadAsStringAsync();

                //the line below is the error******** 
                return Json(new { HttpStatusCode = HttpStatusCode.OK });
        }
    }
使用系统;
使用System.Collections.Generic;
Net系统;
使用System.Net.Http;
使用系统文本;
使用System.Threading.Tasks;
使用System.Web.Http;
使用System.Web.Http.Results;
使用System.Web.Mvc;
//类和命名空间详细信息已删除,以保持此文章简短
公共异步任务帖子(字符串url、字符串内容数据、字典标题)
{
使用(var client=new HttpClient())
{
var response=wait client.PostAsync(url、数据);
var result=await response.Content.ReadAsStringAsync();
//下面的一行是错误*******
返回Json(新的{HttpStatusCode=HttpStatusCode.OK});
}
}
我还尝试了
install package System.Json
,但没有效果

我知道可能还有其他错误,代码在我一小时前启动时从未运行过,但我不明白为什么
Json
无法识别


这来自类库(如果有关系的话)

该方法是Web API的
ApicController
的助手方法,应该在
ApicController
派生类中调用

public class MyApiController : System.Web.Http.ApiController {

    public async Task<IHttpActionResult> Post(string url, StringContent data, Dictionary<string, string> headers) {
        using (var client = new HttpClient()) {
            var response = await client.PostAsync(url, data);
            var result = await response.Content.ReadAsStringAsync();

            return Json(new { HttpStatusCode = HttpStatusCode.OK });
        }
    }    
}

该方法是在任何类或命名空间之外定义的@彼得伯恩斯,对不起。不,我只是删除了它以保持文章简短。更新以使其清晰。SorryAh,如果我从Controller继承,我想我可以返回内容。@MyDaftQuestions
Controller
也有一个
Json
helper方法。你可能应该更新你的问题,以明确你在做什么。由于示例中使用的类型,因此假设为WebAPI。
public class MyController : Controller {

    public async Task<ActionResult> Post(string url, StringContent data, Dictionary<string, string> headers) {
        using (var client = new HttpClient()) {
            var response = await client.PostAsync(url, data);
            var result = await response.Content.ReadAsStringAsync();

            return Json(new { HttpStatusCode = HttpStatusCode.OK }, JsonRequestBehavior.AllowGet);
        }
    }    
}