Visual Studio 2019Asp.Net Core 3.0
A。不支持的介质类型代码
$.ajax({
url: this.url,
data: jsonDataParameter,
cache: false,
type: "Post",
dataType: 'JSON',
contentType: "application/json",
success: function (data) {}
});
B。成功的请求代码
$.ajax({
url: this.url,
data: JSON.stringify(jsonDataParameter),
cache: false,
type: "Post",
dataType: 'JSON',
contentType: "application/json",
success: function (data) {}
});
以下是我的问题:这是功能还是Bug?如果是功能,为什么?
谢谢你。
contentType
是您发送的数据类型,application/json; charset=utf-8
是发送json数据的常见类型。
在您的情况下,数据{a:1,b:2}
只是一个Javascript对象,因此您需要使用JSON.stringify()
方法将Javascript对象或值转换为JSON字符串。
由于您的内容类型是application/json;
,因此需要使用[FromBody]并根据您的情况将数据作为对象接收。