我的Ajax調用看起來就像是:的jQuery 1.5.1 AJAX JSON數據是在控制器
$.ajax({
type: "POST",
url: "/Home/GenerateExportReport",
data: "{ 'fromDate': '2004-12-01', 'toDate': '2011-12-01', 'requestorId': = '1'}",
async: false,
cache: false,
dataType: "json",
//contentType: 'application/json; charset=utf-8',
success: function (data) {
alert("success");
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(errorThrown + " text:" + textStatus + "request " + XMLHttpRequest);
}
});
我的控制器:
[HttpPost]
public ActionResult GenerateExportReport(string data)
{
. . .
}
的呼叫工作,但JSON數據沒來壽控制器出於某種原因,string data
在每次調用時均爲NULL。
我也嘗試了一些修正從這個鏈接
修復jQuery.ajaxSetup()
從該鏈接JQuery 1.5 and new "Text JSON" datatype沒有幫助
修復的contentType:"application/json; charset=utf-8"
,從該鏈接Sending String Data to MVC Controller using jQuery $.ajax() and $.post() 也不能工作,當我設置contentType: "application/json; charset=utf-8"
,我得到錯誤代碼500內部服務器錯誤
也正如其中一個帖子jQuery 1.5.1 breaks all ajax() calls所述,它可能是jQuery validation plugin
所以目前我沒有刪除r從我的網頁中引用此腳本。
有什麼想法?
PS 字符串中的數據({ 'fromDate': '2004-12-01', 'toDate' ... }
)僅僅是一個例子,我有非常大的JSON字符串,我需要傳遞給控制器:
["ONE", "0", "1", "0", "0", "0", "0", "0", "0", "1", "TWO", "281", "5174", "70", "3406", "1405", "300", "4632", "1522", "16790", "TREE", "13", "174", "4", "119", "32", "18", "94", "45", "499", "FOUR", "28", "931", "17", "755", "414", "17", "1138", "353", "3653", "FIVE", "2", "30", "0", "12", "8", "0", "12", "3", "67", "SIX", "13", "250", "7", "173", "77", "18", "247", "49", "834", "9am", "0", "2", "0", "0", "0", "0", "1", "1", "4", "SEVEN", "185", "2838", "45", "2100", "828", "314", "2324", "1223", "9857", "EIGHT", "173", "3662", "23", "1798", "612", "95", "2007", "445", "8815", "NINE", "308", "5277", "52", "3800", "1842", "154", "5548", "1910", "18891", "TEN", "17", "233", "3", "145", "69", "21", "199", "70", "757", "Total", "1020", "18572", "221", "12308", "5287", "937", "16202", "5621", "60168"]