C# datatable的上下文不存在接收错误

C# datatable的上下文不存在接收错误,c#,model-view-controller,datatable,C#,Model View Controller,Datatable,我正在创建一个数据表(下面是我的方法)。我是否遗漏了任何我收到错误信息的原因 当前上下文中不存在名称“Context” public void GetEmployees() { 字符串cs=ConfigurationManager.ConnectionString[“DBCS”].ConnectionString; 列出员工=新列表(); 使用(SqlConnection con=newsqlconnection(cs)) { SqlCommand cmd=新的SqlCommand(“spGet

我正在创建一个数据表(下面是我的方法)。我是否遗漏了任何我收到错误信息的原因

当前上下文中不存在名称“Context”

public void GetEmployees()
{
字符串cs=ConfigurationManager.ConnectionString[“DBCS”].ConnectionString;
列出员工=新列表();
使用(SqlConnection con=newsqlconnection(cs))
{
SqlCommand cmd=新的SqlCommand(“spGetEmployees”,con);
cmd.CommandType=CommandType.storedProcess;
con.Open();
SqlDataReader rdr=cmd.ExecuteReader();
while(rdr.Read())
{
员工=新员工();
employee.Id=Convert.ToInt32(rdr[“Id”]);
employee.FirstName=rdr[“FirstName”].ToString();
employee.LastName=rdr[“LastName”].ToString();
employee.Gender=rdr[“Gender”].ToString();
employee.JobTitle=rdr[“JobTitle”].ToString();
employee.WebSite=rdr[“网站”].ToString();
employee.Salary=Convert.ToInt32(rdr[“Salary”]);
employee.HireDate=Convert.ToDateTime(rdr[“HireDate”]);
employees.Add(employees);
}
}
JavaScriptSerializer js=新的JavaScriptSerializer();
Context.Response.Write(js.Serialize(employees));
}

有人能帮我吗?

如果您想返回json字符串,可以在MVC中使用
Content
方法

public ActionResult GetEmployees()
        {
            ...
            return Content(js.Serialize(employees), "application/json"); 
        }

如果要返回json字符串,可以在MVC中使用
Content
方法

public ActionResult GetEmployees()
        {
            ...
            return Content(js.Serialize(employees), "application/json"); 
        }

此代码位于哪里?在我的Controller.cs文件中,何时发生错误?在测试期间或在浏览器中运行应用程序时?在我构建应用程序时。错误显示在我的错误列表中。您是否在任何地方声明了
Context
?您的意思是
HttpContext
?此代码位于哪里?在我的Controller.cs文件中,何时发生错误?在测试期间或在浏览器中运行应用程序时?在我构建应用程序时。错误显示在我的错误列表中。您是否在任何地方声明了
Context
?你的意思是
HttpContext