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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With