ASP.Net Core 1.0でいくつかのパラメータを使用してリクエストを送信したいと思います(問題があるかどうかわかりません)。ASP.Net MVCはajax呼び出しのパラメータをマップしません
私は次のモデルがあります:
function sendRegistration(nodeName, nodeType) {
var model = {
ServiceType: $("#serviceType").html(),
BatchTimeout: $("#batchTimeout").html(),
BatchSize: $("#batchSize").html(),
FinishingType: $("#finishingType").html()
};
var request = {
nodeName: nodeName,
nodeType: nodeType,
model: model
}
//$.post('@Url.Action("SendRegistration")', request);
$.ajax({
url: '@Url.Action("SendRegistration")',
type: "POST",
dataType: 'json',
data: JSON.stringify(request),
async: false,
cache: false,
traditional: true,
contentType: 'application/json'
});
}
しかし、サーバー上:私もそれを呼び出そうとJSを持っている
public void SendRegistration(string nodeName, NodeTypeEnum nodeType, RegistrationConfigContract model)
{
}
:私は、コントローラのメソッド次いる
[DataContract]
public class RegistrationConfigContract
{
[DataMember]
public string ServiceType { get; set; }
[DataMember]
public int BatchTimeout { get; set; }
[DataMember]
public int BatchSize { get; set; }
[DataMember]
public ActorFinishingTypeEnum FinishingType { get; set; }
}
を私はいつもnullを取得しますが、JS側ではすべてがうまくいますが、Chrome/Edgeデバッガによると、
私はここで間違っていますか?私はこの問題のためにgoogledコードを使用しようとしましたが、動作しません。
生のHTTPリクエスト:
POST http://localhost:8080/Configuration/SendRegistration HTTP/1.1
Host: localhost:8080
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0
Accept: application/json, text/javascript; q=0.01
Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
DNT: 1
Content-Type: application/json
X-Requested-With: XMLHttpRequest
Referer: http://localhost:8080/Configuration
Content-Length: 156
X-Compress: 1
Proxy-Authorization: 6e9b34bd44817cf5c254e1ccb4fe7b31ecd526ea9e025e06a16baca626af6be0ea7fa102c2205f0e
Connection: keep-alive
{"nodeName":"zhdp","nodeType":"DocumentProducer","model":{"ServiceType":"jjjjjj","BatchTimeout":"33535","BatchSize":"6666","FinishingType":"UpdateMessage"}}
私は答え自分自身を見つけましたが、とにかくリンクに感謝、それはいくつかの興味深い持っていますinfo in。 –