Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.Web.HttpRequestBase does not contain a definition for '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:

CreateResponse method in asp.net Web API

complete error is:

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

do you see what I'm doing wrong? maybe something wrong with whats inside the CreateResponse method... thanks

like image 800
noobieDev Avatar asked Jun 18 '14 14:06

noobieDev


1 Answers

I have a feeling you're inheriting the wrong base controller type. If you're using WebAPI, you should inherit from ApiController, not Controller.

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.

like image 121
Steven V Avatar answered Sep 21 '22 18:09

Steven V