简体   繁体   中英

jQuery datatable - ASP.NET controller parameter always null

I have the following JavaScript function...

function loadTable(date: string) {
  $('#myDataTable').DataTable({
    "bServerSide": false,
    "sAjaxSource": "Date/GetValuesFromDate",
    "data": date
    "bAutoWidth": false,
    "bProcessing": true,
    "aoColumns": [
      { "sName": "MESSAGE" },
      { "sName": "DATE" },
      { "sName": "STATUS" }
    ]
    "bDestroy":true
  });

...

That calls the following controller on my ASP.NET WEb Application...

public class DateController : Controller
{
  private RegistrationDbContext _context;

  public HomeController(RegistrationDbContext context)
  {
    _context = context;
  }

  public ActionResult GetValuesFromDate(string date)
  {
    // Some code here...
    return Json(new
      {
        aaData = results;
      });
  }
}

However, the value of the string date is always null. I saw that the loadTable() function does contain the date so I have no clue now how to pass that out to the Controller itself...

I hardcoded the date and everything works wonderfull so the only missing piece here is the binding between the JavaScript function and the Controller...

Any pointers? Thanks!

Trying wrapping up the data param in {} IE

'data': {'date': date}

OR you could directly append it to your source url I think as a query string since it is a GET...

"sAjaxSource": "Date/GetValuesFromDate?date=" + date

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM