我知道这个问题已被发布了一千次,但我尝试了所有解决方案都无济于事。
我有这个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
每当调用控制器时,查看调试器中的monitor变量,我看到所有值都设置为Nothing。
知道可能导致这种情况的原因吗?
答案 0 :(得分:0)
基于您在JSON中显示的数据。您需要设置monitor
$.ajax({
url: '@Url.Action("submitMonitor", "Home")',
type: 'GET',
contentType: 'application/json',
data: {monitor:data}
});