【发布时间】:2021-06-29 15:22:59
【问题描述】:
虽然这是大约 2 年前提出的问题,但我仍然面临这个问题,没有办法摆脱它。有没有办法在 Asp.net Core 3.1 中设置 JSON 对象的最大大小?除了 .Net core(或者我可能还没有找到)之外,在其他 .Net 框架中还有其他方法可以做到这一点。
How to Set Max Json Length in .net core
我有长度约为 3k 的 JSON 对象数组,具有大约 20 个对象的同一文件工作正常,但随着我增加大小,控制器方法中的数据变为空(即使在 DOM 中检查时,console.log 也会显示确切的数组对象)。
console.log(candidate_List);
$.ajax({
url: '@Url.Action("Insert_Candidates")',
data: { "selected_list": candidate_List },
type: "POST",
dataType: "json",
async: true,
success: function (response) {
alert(response.d);
},
failure: function (response) {
alert("fail");
}
});
[HttpPost]
public async Task<IActionResult> Insert_Candidates([FromForm]List<CandidateDTO> selected_list)
{
string result = "";
if (ModelState.IsValid)
{
}
}
【问题讨论】:
-
你有没有尝试过这里的建议:maximum-http-request-size-for-asp-web-api-with-json?
-
我使用的是 MVC 和 Asp.net webforms,但在这里我在 .net 核心项目中没有 webconfig 文件,我可以在其中添加 MaxRequestLength。 (如果您有知识,请告诉我,我会尝试这种方式)
-
为什么是
[FromForm]?你是在正文中发送application/jsonJSON,还是在正文中发送application/x-www-url-formencoded表单数据?请参阅:differences in application/json and application/x-www-form-urlencoded 和 Jquery Ajax Posting JSON to webservice。 -
@RameezJaved 在部署 Asp.Net Core Web 应用程序时,web.config 是自动生成的,您可以将一个添加到您的解决方案中,并且在发布到服务器时仍然会使用它。跨度>
-
@dbc 我正在发送 json 数据,
标签: c# asp.net json ajax asp.net-core