由于某些原因,我必须在视图中新建FormData()并传递给视图中的API,javascript如下所示:
pushButton.addEventListener("click", function (e) {
var url = '@Url.Action("GetData", "SessionData")';
var formData = new FormData();
formData.append('DateFrom', '2022-7-1');
formData.append('DateTo', '2022-7-5');
formData.append('ItemCode', 'AK911');
$.ajax({
url: url,
type: "POST",
data: formData,
processData: false,
contentType: 'multipart/form-data',
success: function (result, status, xhr) { dosomething}
});在后端SessionDataContoller中,我创建了httpPost记录
[HttpPost("GetData")]
[Consumes("multipart/form-data")]
public async Task<IActionResult> GetData([FromForm] FormQuery query)
{
return ProcessByteResponse(await webService.GetQueryData(query));
}当我运行它时,它总是返回:
{"type":"https://tools.ietf.org/html/rfc7231#section-6.5.1","title":"One or more validation errors occurred.","status":400,"traceId":"00-da6621225f50794e9130b4a212996da2-6e46d4edf1f67e43-00","errors":{"":["Failed to read the request form. Missing content-type boundary."]}}我能知道些什么吗?,因为我需要将表单绑定到视图中,但我不能在html正文中使用表单标记。
发布于 2022-09-19 17:06:50
您的content-type头缺少强制的boundary参数,您无法预测该参数。
告诉jQuery不要设置content-type。允许底层浏览器API从FormData对象生成它。
processData: false,
contentType: false,https://stackoverflow.com/questions/73776903
复制相似问题