问题描述
我在这个方法上遇到这个错误:
I'm getting this error on this method:
[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;
}
我的控制器正在实施控制器:
my controller is implementing Controller:
public class HomeController : Controller
{
我发现了这个问题,但答案对我没有帮助:
I found this question, but the answer didn't help me:
完整错误是:
你看到我做错了吗?也许在 CreateResponse
方法中有什么问题...谢谢
do you see what I'm doing wrong? maybe something wrong with whats inside the CreateResponse
method... thanks
推荐答案
我有一种感觉,你继承了错误的基本控制器类型。如果您使用的是WebAPI,则应该继承自 ApiController
,而不是 Controller
。
I have a feeling you're inheriting the wrong base controller type. If you're using WebAPI, you should inherit from ApiController
, not Controller
.
在 ApiController
中,请求
是 System.Net.Http。 HttpRequestMessage
。在控制器
中,请求
是 System.Web.HttpRequestBase
。所以扩展方法很接近,但是不正确的类型会给你签名方法不匹配。
In ApiController
, Request
is System.Net.Http.HttpRequestMessage
. In Controller
, Request
is System.Web.HttpRequestBase
. So the extension method is close, but the incorrect types which is giving you the signature method mismatch.
这篇关于System.Web.HttpRequestBase不包含'CreateResponse'的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!