Using an array as fnServerParams, and having MVC recognise the type properly...
Using an array as fnServerParams, and having MVC recognise the type properly...
jonwah
Posts: 4Questions: 0Answers: 0
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
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
This discussion has been closed.
Replies
Allan
[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.
Allan