0

I have an object selectedDocTypes as [23,45,78]

I need to pass it as a parameter to my controller action. But the value is not getting assigned to parameter, it is null.

Here is code:

JS:

function addNewIssue(accountSID,selectedDocTypes, callback) {
var Data = { accountSID: accountSID, selectedDocTypes: selectedDocTypes };
$.ajax(landforceAPIURL + '/AddNewIssue', {
        cache: false,
        data: Data,
        success: function (data) {
             if (callback)
                    callback(data)
                },
        error: dataContext.queryFailed
        });
};

C#:

[HttpGet, Route("AddNewIssue")]
public string AddNewIssue(string accountSID,int[] selectedDocTypes)
{...}
surajgalande
  • 135
  • 1
  • 2
  • 7

2 Answers2

0

Assuming that you have correctly defined selectedDocTypes in JavaScript as an array, You have to specify contentType send to server in your ajax call, like:

$.ajax(landforceAPIURL + '/AddNewIssue', {
        cache: false,
        data: Data,
        contentType: "application/json; charset=utf-8", //content type send to sever
Habib
  • 219,104
  • 29
  • 407
  • 436
0

I second what @haz commented.

However for this issue, this answer seems to have it covered: https://stackoverflow.com/a/13255459/4349196.

Another possible solution is to use custom JavaScript to construct a URL like:

...accountSID=jSmith&selectedDocTypes=23&selectedDocTypes=45&selectedDocTypes=78

See here for a related example: http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx/.

Community
  • 1
  • 1