Ajax array post using ASP.NET MVC? -



Ajax array post using ASP.NET MVC? -

here acript created generate array:

var data_points = $("#bcc_datapoint_selection").find("input:checked").map(function () { homecoming $(this).val(); }).get();

console log output:

["3","4","6"]

ajax post script:

$.ajax({ url: '@url.action("bccgetmeterreadingschart", "widget")', type: 'post', data: { datapoints: data_points }, success: function (result) { $("#bcc_chart").html(result); }, error: function () { alert("seçilen kritere uygun veri bulunamadı!"); } }); //end ajax

controller method:

public actionresult bccgetmeterreadingschart(string[] datapoints) { // code homecoming json("", jsonrequestbehavior.allowget); }

debug output:

datapoints : null

request info output:

datapoints%5b%5d=3&datapoints%5b%5d=4&datapoints%5b%5d=6

what missing? problem in ajax function? or problem?

try setting traditional parameter true ajax request:

$.ajax({ url: '@url.action("bccgetmeterreadingschart", "widget")', type: 'post', data: { datapoints: data_points }, traditional: true, success: function (result) { $("#bcc_chart").html(result); }, error: function () { alert("seçilen kritere uygun veri bulunamadı!"); } });

now post payload this:

datapoints=3&datapoints=4&datapoints=6

and model binder happily bind collection of points action argument.

asp.net-mvc arrays jquery

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -