2
私はASP.NET MVCアプリケーションで作業しています。ここでは、sessionStorageに格納されたデータをコントローラに送信する必要があります。このストレージには、キーが「確認済み」のキーと値のペアがあります。値は[1,2,3,4,5]のような数字の配列です。ajaxポストを使用して大きな文字列をコントローラに送信
このアレイをコントローラに送信する必要があります。このアレイが長すぎる場合を除いて、すべて正常に動作します。私は設定を変更しようとしました:
<appSettings>
<add key="aspnet:MaxJsonDeserializerMembers" value="1000000" />
</appSettings>
と
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="1000000" />
</webServices>
</scripting>
</system.web.extensions>
が、何も動作していないようにみえます。配列があまり長くない場合にのみうまく動作します。 は、ここに私のコードです:
スクリプト:コントローラー
$(".enviar").click(function() {
getSelectedItems();
var seleccion = sessionStorage.confirmed;
$.ajax({
url: "/Controller/Action",
type: "POST",
//data: { confirm: JSON.stringify(seleccion) },
data: JSON.stringify({ confirm: seleccion }),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (returndata) {
window.location = "@Url.Action("SomeAction","Controller")";
},
error: function (returndata) {
window.location.href = "@Url.Action("AnotherAction","Controller")";
}
});
//sessionStorage.clear();
});
:
[HttpPost]
public ActionResult Action(string confirm)
{
if (!String.IsNullOrEmpty(confirm))
{
confirm = confirm.Substring(1, confirm.Length - 2);
var confirmadas = confirm.Split(',');
foreach (var id in confirmadas)
{
//change things in DB
}
return Json(new { ok = true, newurl = Url.Action("SomeAction", "Controller") });
}
return Json(new { ok = false, newurl = Url.Action("SomeAction", "Controller") });
}
が助けてください、私はほとんどすべてを試みたのだが、時々動作しますが、他の回は、それはdoesnの't。
ありがとうございます。文字列に配列1.join