【发布时间】:2014-04-14 12:02:33
【问题描述】:
"[\"1454\",\"1455\",\"1456\",\"1457\",\"1458\",\"1459\"]"
我在我作为 json.stringify 发送的操作方法中的字符串变量中获取了一个 json 字符串。 这些是 jqgrid 中选定行的 id ..
我只想创建一个数组 我得到了。我不想要其他人 比如反斜杠或正向或双引号。
你能帮帮我吗?这在 C# 中怎么可能
Controller::
public ActionResult ExportSelectedData(string SelectedRows)
{
}
View Code::
function genGraph() {
// location.href = "/WebReports/BatchReport";
var selRowIds = $("#list1").jqGrid('getGridParam', 'selarrrow');
var Array = JSON.stringify(selRowIds);
$.ajax({
type: 'POST',
url: '/WebReports/ExportSelectedData',
data: "{'SelectedRows':'" + Array + "'}",
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (returnValue) {
location.href = "/WebReports/Download?file=" + returnValue.File;
}
});
alert(Array);
【问题讨论】:
-
可能你使用
selRowIds.join()(或selRowIds.join(","))来制作字符串1454,1455,1456,1457,1458,1459而不是["1454","1455","1456","1457","1458","1459"]会更容易。所以你可以使用data: {SelectedRows: selRowIds.join()}作为Ajax 的参数。在服务器端,您可以使用string[] selRows = SelectedRows.split(',');来解析数据。 -
您可以尝试将the approach 与
ModelBinder一起使用,或者将int[]或string[]作为属性here 的简单使用对象交替使用。