2013-02-07 13 views
1

這裏是我創建以產生陣列的acript:使用ASP.NET MVC的Ajax數組後?

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

控制檯日誌輸出:

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

Ajax的後腳本:

$.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 

控制器方法:

public ActionResult BccGetMeterReadingsChart(string[] dataPoints) 
{ 
    // Some code 
    return Json("", JsonRequestBehavior.AllowGet); 
} 

調試輸出:

dataPoints : null 

請求數據輸出:

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

我缺少什麼?這是Ajax函數中的問題嗎?還是另一個問題?

回答

2

嘗試將traditional參數設置爲TRUE您的AJAX請求:

$.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ı!"); 
    } 
}); 

現在POST有效載荷,將是這樣的:

dataPoints=3&dataPoints=4&dataPoints=6 

和模型粘合劑會很樂意結合點的集合到你的行動論點。

+0

你需要寶貴的幫助** [這裏](http://stackoverflow.com/questions/14743271/how-can-i-modify-my-below- mentioned-code-to-display-the-same-validation - 消息)** – SMC

+0

非常感謝... –