0

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!

5
  • In JavaScript you have "data": date, this means the date being sent has parameter name of data. Try changing it to "date":date Commented Dec 14, 2015 at 19:48
  • I changed to "date":date and it is still null. Am I missing something? Commented Dec 14, 2015 at 19:53
  • Try capturing the sent information via Fiddler and show us the request that is being sent. Commented Dec 14, 2015 at 19:54
  • What time of object is date? Commented Dec 14, 2015 at 19:55
  • date is a string object (like this "12/14/2015") Commented Dec 14, 2015 at 19:55

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

2 Comments

Appending the date to the sAjaxSource worked! Thanks a lot!. I will try to investigate it further though as I don't like that design as a permanent solution. Thanks!
Yeah, I know that is icky and I wouldn't recommend doing it permanently...I haven't played with DataTables for awhile though so I was offering it up as an alternative solution and one that hopefully will get you along enough until you can implement a better one

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.