我浏览了很多关于这个主题的帖子,但到目前为止我还没有解决我的问题。我是 MVC / Jquery 的新手,所以我可能错过了答案。
我希望从 jqGrid 返回所有行。我使用 Oleg 的示例代码进行 jqGrid 处理:
sendData = function (data) {
var dataToSend = JSON.stringify(data);
alert("The following data are sending to the server:\n" + dataToSend);
$.ajax({
type: "POST",
url: '@Url.Action("Update", "WatchList")',
dataType: "json",
data: dataToSend,
loadonce: true,
contentType: "application/json; charset=utf-8",
success: function (response, textStatus, jqXHR) {
// remove error div if exist
$('#' + grid[0].id + '_err').remove();
alert("Updates Complete");
},
error: function (jqXHR, textStatus, errorThrown) {
// remove error div if exist
$('#' + grid[0].id + '_err').remove();
// insert div with the error description before the grid
grid.closest('div.ui-jqgrid').before(
'<div id="' + grid[0].id + '_err" style="max-width:' + grid[0].style.width +
';"><div class="ui-state-error ui-corner-all" style="padding:0.7em;float:left;"><span class="ui-icon ui-icon-alert" ' +
'style="float:left; margin-right: .3em;"></span><span style="clear:left">' +
decodeErrorMessage(jqXHR, textStatus, errorThrown) + '</span></div><div style="clear:left"/></div>');
}
$("#sendAll").click(function () {
var localGridData = grid.jqGrid('getGridParam', 'data');
sendData(localGridData);
});
};
帖子的提琴手输出是:
POST http://localhost:49323/WatchList/Update HTTP/1.1
Host: localhost:49323
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0
Accept: application/json, text/javascript, */*; q=0.01
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/json; charset=utf-8
X-Requested-With: XMLHttpRequest
Referer: http://localhost:49323/WatchList/Edit
Content-Length: 3645
Cookie: __RequestVerificationToken=flUoW7U12gHRfOVMNiLu_tW4G_oVI4TwxvAYKOU9arGI014KWFKUKjUbgjbZStLb7n1TGmU22NtoQjAb26bmjcccjg8x6skcL1zbP_o2y5I1; .ASPXAUTH=D968251D718DEF7CA0C9D4A6BD2750F9923CBF554FC0B058772C753C4305682578C207F7367B6D61F80F84CBDCA5C130126AE2CC5E1715FA897122DEB68B3B40C86816C32A6F047891794A732F4A7A3499064220077793B5F1313813FFC21D01
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
[{"Date":"Fri 22 March 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"0"},{"Date":"Sat 23 March 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"1"},{"Date":"Sun 24 March 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"2"},{"Date":"Mon 25 March 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"3"},{"Date":"Tue 26 March 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"4"},{"Date":"Wed 27 March 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"5"},{"Date":"Thu 28 March 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"6"},{"Date":"Fri 29 March 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"7"},{"Date":"Sat 30 March 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"8"},{"Date":"Sun 31 March 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"9"},{"Date":"Mon 1 April 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"10"},{"Date":"Tue 2 April 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"11"},{"Date":"Wed 3 April 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"12"},{"Date":"Thu 4 April 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"13"},{"Date":"Fri 5 April 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"14"},{"Date":"Sat 6 April 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"15"},{"Date":"Sun 7 April 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"16"},{"Date":"Mon 8 April 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"17"},{"Date":"Tue 9 April 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"18"},{"Date":"Wed 10 April 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"19"},{"Date":"Thu 11 April 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"20"},{"Date":"Fri 12 April 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"21"},{"Date":"Sat 13 April 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"22"},{"Date":"Sun 14 April 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"23"},{"Date":"Mon 15 April 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"24"},{"Date":"Tue 16 April 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"25"},{"Date":"Wed 17 April 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"26"},{"Date":"Thu 18 April 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"27"},{"Date":"Fri 19 April 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"28"},{"Date":"Sat 20 April 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"29"},{"Date":"Sun 21 April 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"30"},{"Date":"Mon 22 April 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"31"},{"Date":"Tue 23 April 2013","Night":"False","Morning":"False","Afternoon":"False","Evening":"False","id":"32"}]
控制器接收到的参数为空?我没有将数据直接导入的模型,因为网格列是动态创建的,因此我需要解析原始数据。在我的控制器操作中我需要什么来获取发布数据?