[英]JSON object passed to Controller is NULL
我知道這個問題已經發布了數千次,但是我嘗試了所有解決方案都無濟於事。
我有這個JSON對象:
{
"manufacture":"HP",
"model":"testModel",
"serialNumber":"testSerial",
"description":"Test Description",
"checkIn":true,
"stand":false,
"tilt":true,
"pivot":false,
"heightAdjust":true,
"size":27,
"portTypes":"2 VGA",
"resolution":"1080P"
}
我將此JSON對象傳遞給控制器
Function submitMonitor(monitor As Monitor)
Return False
End Function
傳遞給控制器的ajax調用如下:
jQuery.ajaxSettings.traditional = true;
$.ajax({
url: '@Url.Action("submitMonitor", "Home")',
type: 'GET',
contentType: 'application/json',
//contentType: "application/json; charset=utf-8",
//dataType: 'json',
//processData: true,
data: JSON.stringify(data)
});
我嘗試過:
data:data
我試過沒有ajaxSettings.traditional行。 我已經嘗試過打開或關閉已注釋的塊,但是仍然沒有運氣。
這是它應該傳遞給的類。
Public Class Monitor : Inherits HardwareData
Public stand As Boolean
Public tilt As Boolean
Public pivot As Boolean
Public heightAdjust As Boolean
Public size As Integer
Public portTypes As String
Public resolution As String
End Class
這是Monitor繼承的類:
Public Class HardwareData
Public key As Integer
Public manufacture As String
Public model As String
Public serialNumber As String
Public createdBy As String
Public createdTimeStamp As Date
Public description As String
Public checkIn As Boolean
End Class
每當調用控制器時,只要在調試器中查看監視變量,我都會看到所有值都設置為Nothing。
知道是什么原因造成的嗎?
根據您以JSON顯示的數據。 您需要設置monitor
$.ajax({
url: '@Url.Action("submitMonitor", "Home")',
type: 'GET',
contentType: 'application/json',
data: {monitor:data}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.