Ich erhalte diesen Fehler:
Die JSON-Anforderung war zu groß, um deserialisiert zu werden.
Hier ist ein Szenario, in dem dies auftritt. Ich habe eine Länderklasse, die eine Liste der Schifffahrtshäfen dieses Landes enthält
public class Country
{
public int Id { get; set; }
public string Name { get; set; }
public List<Port> Ports { get; set; }
}
Ich verwende KnockoutJS auf der Clientseite, um kaskadierende Dropdowns zu erstellen. Wir haben also eine Reihe von zwei Dropdowns, von denen der erste das Land und der zweite die Häfen dieses Landes ist.
Bisher funktioniert alles einwandfrei, dies ist mein clientseitiges Skript:
var k1 = k1 || {};
$(document).ready(function () {
k1.MarketInfoItem = function (removeable) {
var self = this;
self.CountryOfLoadingId = ko.observable();
self.PortOfLoadingId = ko.observable();
self.CountryOfDestinationId = ko.observable();
self.PortOfDestinationId = ko.observable();
};
k1.viewModel = function () {
var marketInfoItems = ko.observableArray([]),
countries = ko.observableArray([]),
saveMarketInfo = function () {
var jsonData = ko.toJSON(marketInfoItems);
$.ajax({
url: 'SaveMarketInfos',
type: "POST",
data: jsonData,
datatype: "json",
contentType: "application/json charset=utf-8",
success: function (data) {
if (data) {
window.location.href = "Fin";
} else {
alert("Can not save your market information now!");
}
},
error: function (data) { alert("Can not save your contacts now!"); }
});
},
loadData = function () {
$.getJSON('../api/ListService/GetCountriesWithPorts', function (data) {
countries(data);
});
};
return {
MarketInfoItems: marketInfoItems,
Countries: countries,
LoadData: loadData,
SaveMarketInfo: saveMarketInfo,
};
} ();
Das Problem tritt auf, wenn ein Land wie China ausgewählt wird, das viele Häfen hat. Wenn Sie also drei- oder viermal "China" in Ihrem Array haben und ich es zum Speichern an den Server senden möchte. Der Fehler tritt auf.
Was soll ich tun, um dies zu beheben?