我需要將選中的複選框代碼從JavaScript傳遞到C#。我能夠通過JSON發送代碼。而我的JSON值就像JArray一樣。我在標題中得到了例外。無法將Newtonsoft.Json.Linq.JArray轉換爲Newtonsoft.Json.Linq.JToken。當我通過json時發生錯誤
JSON:
{
"Items": [
"100066",
"100067"
]
}
C#:
public ActionResult UpdateTransportRequests()
{
string json;
using (var reader = new StreamReader(Request.InputStream))
{
json = reader.ReadToEnd();
}
JObject jo = (JObject)JsonConvert.DeserializeObject(json);
string lineItems = jo.Value<string>("Items");
RequestDataAccess rda = new RequestDataAccess();
decimal reqId = decimal.Parse(lineItems);
rda.ApproveReject_Request(reqId, "A", "");
return Json(new { result = "success" });
}
客戶端:
function approveAll(requestid) {
var items = [];
$('#grid tbody').find('input:checkbox:checked').each(function (index, item) {
var rowIndex = $(this).closest('tr').index();
items.push($('#grid tbody').find('tr:eq(' + rowIndex + ')').find('td:eq(1)').text().replace('TR-', ''));
});
$.ajax({
type: "POST",
url: '@Url.Action("UpdateTransportRequestsAll", "TransportRequest")',
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ "Items": items }),
success: function (response) {
alert(response.result);
},
dataType: "json"
});
}
請幫我解決這個問題錯誤。
這是錯誤? –
我沒有看到一行將JArray轉換爲JToken ... – Sascha