gpt4 book ai didi

asp.net-mvc - System.Web.HttpRequestBase 不包含 'CreateResponse' 的定义

转载 作者:可可西里 更新时间:2023-11-01 15:26:27 24 4
gpt4 key购买 nike

我在这个方法上遇到了这个错误:

        [HttpGet]            
public HttpResponseMessage Search([ModelBinder(typeof(ApiDataTablesModelBinder))] IDataTablesRequest requestModel)
{
var sortedColumn = requestModel.Columns.GetSortedColumns().SingleOrDefault();

bool isDesc = false;
string sortField = "ID";

// get all projects and order them
var projects = lkp_surveyRepo.GetAll();//.OrderBy(sortField, isDesc).ToList();

// filtered projects
var filteredResults = projects;

filteredResults = projects.Where(x => x.code == selectedDistrictID);

var pagedResults = filteredResults.Skip(requestModel.Start).Take(requestModel.Length);
var result = Request.CreateResponse(HttpStatusCode.OK, new DataTablesResponse(requestModel.Draw, pagedResults, filteredResults.Count(), projects.Count()));

return result;
}

我的 Controller 正在实现 Controller :

public class HomeController : Controller
{

我发现了这个问题,但答案对我没有帮助:

CreateResponse method in asp.net Web API

完整的错误是:

Error 13 'System.Web.HttpRequestBase' does not contain a definition for 'CreateResponse' and the best extension method overload 'System.Net.Http.HttpRequestMessageExtensions.CreateResponse(System.Net.Http.HttpRequestMessage, System.Net.HttpStatusCode, T)' has some invalid arguments

你看到我做错了什么了吗? CreateResponse 方法中的内容可能有问题...谢谢

最佳答案

我感觉您继承了错误的基本 Controller 类型。如果您使用的是 WebAPI,您应该继承自 ApiController,而不是 Controller

ApiController中,RequestSystem.Net.Http.HttpRequestMessage。在Controller中,RequestSystem.Web.HttpRequestBase。所以扩展方法很接近,但是不正确的类型给你的签名方法不匹配。

关于asp.net-mvc - System.Web.HttpRequestBase 不包含 'CreateResponse' 的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24288426/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com