Using an array as fnServerParams, and having MVC recognise the type properly...

Using an array as fnServerParams, and having MVC recognise the type properly...

jonwahjonwah Posts: 4Questions: 0Answers: 0
edited March 2012 in DataTables 1.9
Hi guys,

I'm using DataTables 1.9, and it's working great. I add extra parameters to my data calls, and when they are simple types (ints, strings etc) everything goes ok.

However, I'm trying to send an array of integers as a parameter, as below:

[code] "fnServerParams": function (aoData) {
aoData.push({ "name": "EventId", "value": window.EventId });
aoData.push({ "name": "HazardEventIds", "value": window.hazardEventIds });
},[/code]

In the MVC binder I'm using, it's defined as:

[code]
public int EventId { get; set; }

public int[] HazardEventIds { get; set; }
[/code]

(Along with other stuff, of course).

So, EventId gets bound correctly, however I can't seem for the life of me to get the array of ints to bind in MVC. Looking at the GET request, I can see the array is being added to the request parameters correctly (or what seems to be correctly). If I change the binder to be public string, I get the string of ids, i.e "3,4". Is this something to do with the way datatables encodes JSON for the parameters? Any ideas on how to make it bind correctly?

Cheers,


Jono

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    What does Firebug say is being set to the server? I don't know anything about .NET, so you might need to ask in a forum where that domain knowledge is available :-)

    Allan
  • jonwahjonwah Posts: 4Questions: 0Answers: 0
    From Firebug's Params window, from the console GET Request:

    [code]
    EventId 4
    HazardEventIds 5,7
    _ 1332378092664
    iColumns 10
    iDisplayLength 20
    iDisplayStart 0
    mDataProp_0 0
    mDataProp_1 1
    mDataProp_2 2
    mDataProp_3 3
    mDataProp_4 4
    mDataProp_5 5
    mDataProp_6 6
    mDataProp_7 7
    mDataProp_8 8
    mDataProp_9 9
    sColumns
    sEcho 10

    [/code]

    Note: I blanked sColumns when I pasted it in here.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    From that "HazardEventIds" is just a comma separated string, You can split on the comma to get an array. To actually submit an array you would need to have "window.hazardEventIds" as an array, but I've no idea how you would access that.

    Allan
This discussion has been closed.