System.Web.HttpRequestBase不包含'CreateResponse'的定义 [英] System.Web.HttpRequestBase does not contain a definition for 'CreateResponse'

查看:1400
本文介绍了System.Web.HttpRequestBase不包含'CreateResponse'的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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:

asp.net Web API中的CreateResponse方法

完整错误是:


错误13'System.Web.HttpRequestBase'不包含'CreateResponse'的定义
和最佳扩展方法重载
' System.Net.Http.HttpRequestMessageExtensions.CreateResponse(System.Net.Http.HttpRequestMessage,
System.Net.HttpStatusCode,T)'有一些无效的参数

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 方法中有什么问题...谢谢

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'的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆