javascript - MVC controller's string[] parameter is null when posting JSON data -
I post data with jQuery but I have problems with array data. The values given for the MVC controller are always zero.
This is my JavaScript code:
var FilterCategory = $ ('input: checkbox: check'). Map (function () {return.value;}). (); Var posting = $ Post (url, {cursorid: lastid, CatFilter: FilterCategory}); Form data from network:
cursorid: 5434cdc84ba4dd0c40396851 filter [1]: 1 filter []: 3 filter []: 4 Here is the C # side: Public action results GetDataTweets (string cursor, string [] catfilter) {bla bla} Cursorid
< P> This code is here: var posting = $ .post (url, {cursorid: lastid, catfilter: filtercategory}); This is sending a class from MVC perspective, so to package the data you need reciprocal C # class. Create a class to handle that data, for example:
I assume that your catfilter array is a string array:
public class data {public string cursorid {Get; Set;} public string [] CatFilter {get; Set up;}} Then change your controller:
Public functions GetDataTweets (data data) {var s1 = data.cursorid; Var s2 = data.CatFilter [0]; } If CatFilter is a class, then you have to create a catfilter category to map to a javascript version.
Comments
Post a Comment