Getting HttpReques does not contain definition for Form - Datatable server side processingCannot implicitly convert Web.Http.Results.JsonResult to Web.Mvc.JsonResultPOST throws HttpRequestMessage does not contain a definition for FormThe located assembly's manifest definition does not match the assembly referenceBest practice to call ConfigureAwait for all server-side codeServer Side Datatable ProcessingDatatables server side processingServer-side processing DataTableDatatables - Local Server Side ProcessingServer Side datatable crashes on processingServer side processing with datatables and flaskdatatable plugin php and json errrorDataTable with Server-side processing

Are glider winch launches rarer in the USA than in the rest of the world? Why?

Where to place an artificial gland in the human body?

How did C64 games handle music during gameplay?

Spoken encryption

What to do when you reach a conclusion and find out later on that someone else already did?

USA: Can a witness take the 5th to avoid perjury?

Are gangsters hired to attack people at a train station classified as a terrorist attack?

What do I do when a student working in my lab "ghosts" me?

What is a reasonable time for modern human society to adapt to dungeons?

Why do websites not use the HaveIBeenPwned API to warn users about exposed passwords?

High income, sudden windfall

What does the minus sign mean in measurements in datasheet footprint drawings?

How much damage does a magic stone cause when hurled from a sling?

Current relevance: "She has broken her leg" vs. "She broke her leg yesterday"

What do teaching faculty do during semester breaks?

How do I run a game when my PCs have different approaches to combat?

kids pooling money for Lego League and taxes

Terence Tao - type books in other fields?

No-cloning theorem does not seem precise

What is a Union Word™?

What are the exact meanings of roll, pitch and yaw?

Inadvertently nuked my disk permission structure - why?

Can two figures have the same area, perimeter, and same number of segments have different shape?

What exactly makes a General Products hull nearly indestructible?



Getting HttpReques does not contain definition for Form - Datatable server side processing


Cannot implicitly convert Web.Http.Results.JsonResult to Web.Mvc.JsonResultPOST throws HttpRequestMessage does not contain a definition for FormThe located assembly's manifest definition does not match the assembly referenceBest practice to call ConfigureAwait for all server-side codeServer Side Datatable ProcessingDatatables server side processingServer-side processing DataTableDatatables - Local Server Side ProcessingServer Side datatable crashes on processingServer side processing with datatables and flaskdatatable plugin php and json errrorDataTable with Server-side processing






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have the following server side code:



using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using AutoMapper;
using myProject.Models;
using System.Web.Http;
using MyProject.Dtos;

using System.Web.Mvc;
using System.Linq.Dynamic;
using System.Data.Entity;
public class MembersController: Controller

public MembersController()

_context = new ApplicationDbContext();



public ActionResult GetMembers(string query = null)

try

//Creating instance of DatabaseContext class
using (_context)

var draw = Request.Form.GetValues("draw").FirstOrDefault();
var start = Request.Form.GetValues("start").FirstOrDefault();
var length = Request.Form.GetValues("length").FirstOrDefault();



//Paging Size (10,20,50,100)
int pageSize = length != null ? Convert.ToInt32(length) : 0;
int skip = start != null ? Convert.ToInt32(start) : 0;
int recordsTotal = 0;

// Getting all member data
var membersQuery = _context.Members.ToList();



//total number of rows count
recordsTotal = membersQuery.Count();
//Paging
var data = membersQuery.Skip(skip).Take(pageSize).ToList();
////Returning Json Data
return Json(new draw = draw, recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data );




catch (Exception)

throw;







Here's my view:



var table = $("#members").DataTable(
"processing": true, // for show progress bar
"serverSide": true,
"pageLength":5,

ajax:
url: "/api/members",
dataSrc: "",
"type": "POST",
"datatype": "json"

,

columns: [

data: "cardNumber"
,

data: "registrationDate",

,

data: "fullName",

,

data: "address"
,

data: "phoneNumber"
,

data: "email"

]
);


I am getting the following compile errors:




Error CS1061 'HttpRequestMessage' does not contain a definition for 'Form' and no accessible extension method 'Form' accepting a first argument of type 'HttpRequestMessage' could be found (are you missing a using directive or an assembly reference?)



Error CS0029 Cannot implicitly convert type 'System.Web.Http.Results.JsonResult< data>>' to 'System.Web.Mvc.ActionResult'




I am following this tutorial for guidance.



Will appreciate your help










share|improve this question




























    0















    I have the following server side code:



    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using AutoMapper;
    using myProject.Models;
    using System.Web.Http;
    using MyProject.Dtos;

    using System.Web.Mvc;
    using System.Linq.Dynamic;
    using System.Data.Entity;
    public class MembersController: Controller

    public MembersController()

    _context = new ApplicationDbContext();



    public ActionResult GetMembers(string query = null)

    try

    //Creating instance of DatabaseContext class
    using (_context)

    var draw = Request.Form.GetValues("draw").FirstOrDefault();
    var start = Request.Form.GetValues("start").FirstOrDefault();
    var length = Request.Form.GetValues("length").FirstOrDefault();



    //Paging Size (10,20,50,100)
    int pageSize = length != null ? Convert.ToInt32(length) : 0;
    int skip = start != null ? Convert.ToInt32(start) : 0;
    int recordsTotal = 0;

    // Getting all member data
    var membersQuery = _context.Members.ToList();



    //total number of rows count
    recordsTotal = membersQuery.Count();
    //Paging
    var data = membersQuery.Skip(skip).Take(pageSize).ToList();
    ////Returning Json Data
    return Json(new draw = draw, recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data );




    catch (Exception)

    throw;







    Here's my view:



    var table = $("#members").DataTable(
    "processing": true, // for show progress bar
    "serverSide": true,
    "pageLength":5,

    ajax:
    url: "/api/members",
    dataSrc: "",
    "type": "POST",
    "datatype": "json"

    ,

    columns: [

    data: "cardNumber"
    ,

    data: "registrationDate",

    ,

    data: "fullName",

    ,

    data: "address"
    ,

    data: "phoneNumber"
    ,

    data: "email"

    ]
    );


    I am getting the following compile errors:




    Error CS1061 'HttpRequestMessage' does not contain a definition for 'Form' and no accessible extension method 'Form' accepting a first argument of type 'HttpRequestMessage' could be found (are you missing a using directive or an assembly reference?)



    Error CS0029 Cannot implicitly convert type 'System.Web.Http.Results.JsonResult< data>>' to 'System.Web.Mvc.ActionResult'




    I am following this tutorial for guidance.



    Will appreciate your help










    share|improve this question
























      0












      0








      0


      1






      I have the following server side code:



      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Net;
      using AutoMapper;
      using myProject.Models;
      using System.Web.Http;
      using MyProject.Dtos;

      using System.Web.Mvc;
      using System.Linq.Dynamic;
      using System.Data.Entity;
      public class MembersController: Controller

      public MembersController()

      _context = new ApplicationDbContext();



      public ActionResult GetMembers(string query = null)

      try

      //Creating instance of DatabaseContext class
      using (_context)

      var draw = Request.Form.GetValues("draw").FirstOrDefault();
      var start = Request.Form.GetValues("start").FirstOrDefault();
      var length = Request.Form.GetValues("length").FirstOrDefault();



      //Paging Size (10,20,50,100)
      int pageSize = length != null ? Convert.ToInt32(length) : 0;
      int skip = start != null ? Convert.ToInt32(start) : 0;
      int recordsTotal = 0;

      // Getting all member data
      var membersQuery = _context.Members.ToList();



      //total number of rows count
      recordsTotal = membersQuery.Count();
      //Paging
      var data = membersQuery.Skip(skip).Take(pageSize).ToList();
      ////Returning Json Data
      return Json(new draw = draw, recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data );




      catch (Exception)

      throw;







      Here's my view:



      var table = $("#members").DataTable(
      "processing": true, // for show progress bar
      "serverSide": true,
      "pageLength":5,

      ajax:
      url: "/api/members",
      dataSrc: "",
      "type": "POST",
      "datatype": "json"

      ,

      columns: [

      data: "cardNumber"
      ,

      data: "registrationDate",

      ,

      data: "fullName",

      ,

      data: "address"
      ,

      data: "phoneNumber"
      ,

      data: "email"

      ]
      );


      I am getting the following compile errors:




      Error CS1061 'HttpRequestMessage' does not contain a definition for 'Form' and no accessible extension method 'Form' accepting a first argument of type 'HttpRequestMessage' could be found (are you missing a using directive or an assembly reference?)



      Error CS0029 Cannot implicitly convert type 'System.Web.Http.Results.JsonResult< data>>' to 'System.Web.Mvc.ActionResult'




      I am following this tutorial for guidance.



      Will appreciate your help










      share|improve this question














      I have the following server side code:



      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Net;
      using AutoMapper;
      using myProject.Models;
      using System.Web.Http;
      using MyProject.Dtos;

      using System.Web.Mvc;
      using System.Linq.Dynamic;
      using System.Data.Entity;
      public class MembersController: Controller

      public MembersController()

      _context = new ApplicationDbContext();



      public ActionResult GetMembers(string query = null)

      try

      //Creating instance of DatabaseContext class
      using (_context)

      var draw = Request.Form.GetValues("draw").FirstOrDefault();
      var start = Request.Form.GetValues("start").FirstOrDefault();
      var length = Request.Form.GetValues("length").FirstOrDefault();



      //Paging Size (10,20,50,100)
      int pageSize = length != null ? Convert.ToInt32(length) : 0;
      int skip = start != null ? Convert.ToInt32(start) : 0;
      int recordsTotal = 0;

      // Getting all member data
      var membersQuery = _context.Members.ToList();



      //total number of rows count
      recordsTotal = membersQuery.Count();
      //Paging
      var data = membersQuery.Skip(skip).Take(pageSize).ToList();
      ////Returning Json Data
      return Json(new draw = draw, recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data );




      catch (Exception)

      throw;







      Here's my view:



      var table = $("#members").DataTable(
      "processing": true, // for show progress bar
      "serverSide": true,
      "pageLength":5,

      ajax:
      url: "/api/members",
      dataSrc: "",
      "type": "POST",
      "datatype": "json"

      ,

      columns: [

      data: "cardNumber"
      ,

      data: "registrationDate",

      ,

      data: "fullName",

      ,

      data: "address"
      ,

      data: "phoneNumber"
      ,

      data: "email"

      ]
      );


      I am getting the following compile errors:




      Error CS1061 'HttpRequestMessage' does not contain a definition for 'Form' and no accessible extension method 'Form' accepting a first argument of type 'HttpRequestMessage' could be found (are you missing a using directive or an assembly reference?)



      Error CS0029 Cannot implicitly convert type 'System.Web.Http.Results.JsonResult< data>>' to 'System.Web.Mvc.ActionResult'




      I am following this tutorial for guidance.



      Will appreciate your help







      c# json asp.net-mvc datatables






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 26 at 16:08









      bangbangbangbang

      5471 gold badge4 silver badges18 bronze badges




      5471 gold badge4 silver badges18 bronze badges






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Both exception messages are related each other, and seem originated from this using statement which was suspicious:



          using System.Web.Http;


          And this url setting which implies that you want to call Web API controller from DataTable's AJAX callback:



          url: "/api/members", // points to Web API controller


          The first exception occurred because you're using Request property which not originated from HttpContext.Request that returns HttpRequest, instead it came from another Request property in System.Web.Http namespace which returns HttpRequestMessage.



          The second exception occurred because return type of the controller action is System.Web.Mvc.ActionResult, while your Json() method might return System.Web.Http.Results.JsonResult which is part of Web API.



          Judging from your AJAX URL and controller action, you have 2 options:



          1) If you're using MVC controller, remove System.Web.Http namespace and make sure you're using Request from HttpContext.Current like example below:



          var draw = HttpContext.Current.Request.Form.GetValues("draw").FirstOrDefault();
          var start = HttpContext.Current.Request.Form.GetValues("start").FirstOrDefault();
          var length = HttpContext.Current.Request.Form.GetValues("length").FirstOrDefault();


          Then you need to replace AJAX call in DataTable to call the action name like this:



          ajax: 
          url: '@Url.Action("GetMember", "Members")',
          data: ..., // set your data here
          type: "POST",
          dataType: "json"
          ,


          2) If you're using Web API controller, replace System.Web.Mvc.Controller inheritance with System.Web.Http.ApiController, then use proper way to return JSON string from Web API controller:



          public class MembersController: ApiController 

          // ctor
          public MembersController()

          _context = new ApplicationDbContext();



          public IHttpActionResult GetMembers([FromBody] ViewModel model)

          try

          //Creating instance of DatabaseContext class
          using (_context)

          var draw = model.Draw;
          var start = model.Start;
          var length = model.Length;

          // skipped for brevity

          return Ok(new draw = draw, recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data );

          catch (Exception)

          // error handling






          If you choose this approach, you can leave the URL /api/Members as is but the AJAX call's data/dataSrc parameter from DataTable should be modified to pass the viewmodel object because Request property from Web API doesn't have Form property as its member.



          Related issues:



          POST throws HttpRequestMessage does not contain a definition for Form



          Cannot implicitly convert Web.Http.Results.JsonResult to Web.Mvc.JsonResult






          share|improve this answer























          • Hi @Tetsuya, thanks for your insights. I opted for option 1 (MVC Controller) and when I started to debug, I got the following exception on the very first line where it tries to read the value of "draw". This is what I got: Value cannot be null. Parameter name: source

            – bangbang
            Mar 27 at 16:35











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55361591%2fgetting-httpreques-does-not-contain-definition-for-form-datatable-server-side%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Both exception messages are related each other, and seem originated from this using statement which was suspicious:



          using System.Web.Http;


          And this url setting which implies that you want to call Web API controller from DataTable's AJAX callback:



          url: "/api/members", // points to Web API controller


          The first exception occurred because you're using Request property which not originated from HttpContext.Request that returns HttpRequest, instead it came from another Request property in System.Web.Http namespace which returns HttpRequestMessage.



          The second exception occurred because return type of the controller action is System.Web.Mvc.ActionResult, while your Json() method might return System.Web.Http.Results.JsonResult which is part of Web API.



          Judging from your AJAX URL and controller action, you have 2 options:



          1) If you're using MVC controller, remove System.Web.Http namespace and make sure you're using Request from HttpContext.Current like example below:



          var draw = HttpContext.Current.Request.Form.GetValues("draw").FirstOrDefault();
          var start = HttpContext.Current.Request.Form.GetValues("start").FirstOrDefault();
          var length = HttpContext.Current.Request.Form.GetValues("length").FirstOrDefault();


          Then you need to replace AJAX call in DataTable to call the action name like this:



          ajax: 
          url: '@Url.Action("GetMember", "Members")',
          data: ..., // set your data here
          type: "POST",
          dataType: "json"
          ,


          2) If you're using Web API controller, replace System.Web.Mvc.Controller inheritance with System.Web.Http.ApiController, then use proper way to return JSON string from Web API controller:



          public class MembersController: ApiController 

          // ctor
          public MembersController()

          _context = new ApplicationDbContext();



          public IHttpActionResult GetMembers([FromBody] ViewModel model)

          try

          //Creating instance of DatabaseContext class
          using (_context)

          var draw = model.Draw;
          var start = model.Start;
          var length = model.Length;

          // skipped for brevity

          return Ok(new draw = draw, recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data );

          catch (Exception)

          // error handling






          If you choose this approach, you can leave the URL /api/Members as is but the AJAX call's data/dataSrc parameter from DataTable should be modified to pass the viewmodel object because Request property from Web API doesn't have Form property as its member.



          Related issues:



          POST throws HttpRequestMessage does not contain a definition for Form



          Cannot implicitly convert Web.Http.Results.JsonResult to Web.Mvc.JsonResult






          share|improve this answer























          • Hi @Tetsuya, thanks for your insights. I opted for option 1 (MVC Controller) and when I started to debug, I got the following exception on the very first line where it tries to read the value of "draw". This is what I got: Value cannot be null. Parameter name: source

            – bangbang
            Mar 27 at 16:35
















          0














          Both exception messages are related each other, and seem originated from this using statement which was suspicious:



          using System.Web.Http;


          And this url setting which implies that you want to call Web API controller from DataTable's AJAX callback:



          url: "/api/members", // points to Web API controller


          The first exception occurred because you're using Request property which not originated from HttpContext.Request that returns HttpRequest, instead it came from another Request property in System.Web.Http namespace which returns HttpRequestMessage.



          The second exception occurred because return type of the controller action is System.Web.Mvc.ActionResult, while your Json() method might return System.Web.Http.Results.JsonResult which is part of Web API.



          Judging from your AJAX URL and controller action, you have 2 options:



          1) If you're using MVC controller, remove System.Web.Http namespace and make sure you're using Request from HttpContext.Current like example below:



          var draw = HttpContext.Current.Request.Form.GetValues("draw").FirstOrDefault();
          var start = HttpContext.Current.Request.Form.GetValues("start").FirstOrDefault();
          var length = HttpContext.Current.Request.Form.GetValues("length").FirstOrDefault();


          Then you need to replace AJAX call in DataTable to call the action name like this:



          ajax: 
          url: '@Url.Action("GetMember", "Members")',
          data: ..., // set your data here
          type: "POST",
          dataType: "json"
          ,


          2) If you're using Web API controller, replace System.Web.Mvc.Controller inheritance with System.Web.Http.ApiController, then use proper way to return JSON string from Web API controller:



          public class MembersController: ApiController 

          // ctor
          public MembersController()

          _context = new ApplicationDbContext();



          public IHttpActionResult GetMembers([FromBody] ViewModel model)

          try

          //Creating instance of DatabaseContext class
          using (_context)

          var draw = model.Draw;
          var start = model.Start;
          var length = model.Length;

          // skipped for brevity

          return Ok(new draw = draw, recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data );

          catch (Exception)

          // error handling






          If you choose this approach, you can leave the URL /api/Members as is but the AJAX call's data/dataSrc parameter from DataTable should be modified to pass the viewmodel object because Request property from Web API doesn't have Form property as its member.



          Related issues:



          POST throws HttpRequestMessage does not contain a definition for Form



          Cannot implicitly convert Web.Http.Results.JsonResult to Web.Mvc.JsonResult






          share|improve this answer























          • Hi @Tetsuya, thanks for your insights. I opted for option 1 (MVC Controller) and when I started to debug, I got the following exception on the very first line where it tries to read the value of "draw". This is what I got: Value cannot be null. Parameter name: source

            – bangbang
            Mar 27 at 16:35














          0












          0








          0







          Both exception messages are related each other, and seem originated from this using statement which was suspicious:



          using System.Web.Http;


          And this url setting which implies that you want to call Web API controller from DataTable's AJAX callback:



          url: "/api/members", // points to Web API controller


          The first exception occurred because you're using Request property which not originated from HttpContext.Request that returns HttpRequest, instead it came from another Request property in System.Web.Http namespace which returns HttpRequestMessage.



          The second exception occurred because return type of the controller action is System.Web.Mvc.ActionResult, while your Json() method might return System.Web.Http.Results.JsonResult which is part of Web API.



          Judging from your AJAX URL and controller action, you have 2 options:



          1) If you're using MVC controller, remove System.Web.Http namespace and make sure you're using Request from HttpContext.Current like example below:



          var draw = HttpContext.Current.Request.Form.GetValues("draw").FirstOrDefault();
          var start = HttpContext.Current.Request.Form.GetValues("start").FirstOrDefault();
          var length = HttpContext.Current.Request.Form.GetValues("length").FirstOrDefault();


          Then you need to replace AJAX call in DataTable to call the action name like this:



          ajax: 
          url: '@Url.Action("GetMember", "Members")',
          data: ..., // set your data here
          type: "POST",
          dataType: "json"
          ,


          2) If you're using Web API controller, replace System.Web.Mvc.Controller inheritance with System.Web.Http.ApiController, then use proper way to return JSON string from Web API controller:



          public class MembersController: ApiController 

          // ctor
          public MembersController()

          _context = new ApplicationDbContext();



          public IHttpActionResult GetMembers([FromBody] ViewModel model)

          try

          //Creating instance of DatabaseContext class
          using (_context)

          var draw = model.Draw;
          var start = model.Start;
          var length = model.Length;

          // skipped for brevity

          return Ok(new draw = draw, recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data );

          catch (Exception)

          // error handling






          If you choose this approach, you can leave the URL /api/Members as is but the AJAX call's data/dataSrc parameter from DataTable should be modified to pass the viewmodel object because Request property from Web API doesn't have Form property as its member.



          Related issues:



          POST throws HttpRequestMessage does not contain a definition for Form



          Cannot implicitly convert Web.Http.Results.JsonResult to Web.Mvc.JsonResult






          share|improve this answer













          Both exception messages are related each other, and seem originated from this using statement which was suspicious:



          using System.Web.Http;


          And this url setting which implies that you want to call Web API controller from DataTable's AJAX callback:



          url: "/api/members", // points to Web API controller


          The first exception occurred because you're using Request property which not originated from HttpContext.Request that returns HttpRequest, instead it came from another Request property in System.Web.Http namespace which returns HttpRequestMessage.



          The second exception occurred because return type of the controller action is System.Web.Mvc.ActionResult, while your Json() method might return System.Web.Http.Results.JsonResult which is part of Web API.



          Judging from your AJAX URL and controller action, you have 2 options:



          1) If you're using MVC controller, remove System.Web.Http namespace and make sure you're using Request from HttpContext.Current like example below:



          var draw = HttpContext.Current.Request.Form.GetValues("draw").FirstOrDefault();
          var start = HttpContext.Current.Request.Form.GetValues("start").FirstOrDefault();
          var length = HttpContext.Current.Request.Form.GetValues("length").FirstOrDefault();


          Then you need to replace AJAX call in DataTable to call the action name like this:



          ajax: 
          url: '@Url.Action("GetMember", "Members")',
          data: ..., // set your data here
          type: "POST",
          dataType: "json"
          ,


          2) If you're using Web API controller, replace System.Web.Mvc.Controller inheritance with System.Web.Http.ApiController, then use proper way to return JSON string from Web API controller:



          public class MembersController: ApiController 

          // ctor
          public MembersController()

          _context = new ApplicationDbContext();



          public IHttpActionResult GetMembers([FromBody] ViewModel model)

          try

          //Creating instance of DatabaseContext class
          using (_context)

          var draw = model.Draw;
          var start = model.Start;
          var length = model.Length;

          // skipped for brevity

          return Ok(new draw = draw, recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data );

          catch (Exception)

          // error handling






          If you choose this approach, you can leave the URL /api/Members as is but the AJAX call's data/dataSrc parameter from DataTable should be modified to pass the viewmodel object because Request property from Web API doesn't have Form property as its member.



          Related issues:



          POST throws HttpRequestMessage does not contain a definition for Form



          Cannot implicitly convert Web.Http.Results.JsonResult to Web.Mvc.JsonResult







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 27 at 3:39









          Tetsuya YamamotoTetsuya Yamamoto

          17.6k4 gold badges25 silver badges42 bronze badges




          17.6k4 gold badges25 silver badges42 bronze badges












          • Hi @Tetsuya, thanks for your insights. I opted for option 1 (MVC Controller) and when I started to debug, I got the following exception on the very first line where it tries to read the value of "draw". This is what I got: Value cannot be null. Parameter name: source

            – bangbang
            Mar 27 at 16:35


















          • Hi @Tetsuya, thanks for your insights. I opted for option 1 (MVC Controller) and when I started to debug, I got the following exception on the very first line where it tries to read the value of "draw". This is what I got: Value cannot be null. Parameter name: source

            – bangbang
            Mar 27 at 16:35

















          Hi @Tetsuya, thanks for your insights. I opted for option 1 (MVC Controller) and when I started to debug, I got the following exception on the very first line where it tries to read the value of "draw". This is what I got: Value cannot be null. Parameter name: source

          – bangbang
          Mar 27 at 16:35






          Hi @Tetsuya, thanks for your insights. I opted for option 1 (MVC Controller) and when I started to debug, I got the following exception on the very first line where it tries to read the value of "draw". This is what I got: Value cannot be null. Parameter name: source

          – bangbang
          Mar 27 at 16:35









          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55361591%2fgetting-httpreques-does-not-contain-definition-for-form-datatable-server-side%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript