[英]JSON object passed to Controller is NULL
I understand this question has been posted a thousand times, but I have tried every solution to no avail. 我知道这个问题已经发布了数千次,但是我尝试了所有解决方案都无济于事。
I have this JSON object: 我有这个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"
}
I pass this JSON object to the controller which is just 我将此JSON对象传递给控制器
Function submitMonitor(monitor As Monitor)
Return False
End Function
The ajax call to pass to the controller is as follows: 传递给控制器的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)
});
I have tried passing: 我尝试过:
data:data
I have tried without the ajaxSettings.traditional line. 我试过没有ajaxSettings.traditional行。 I have tried with the commented blocks on or off, but still no luck.
我已经尝试过打开或关闭已注释的块,但是仍然没有运气。
Here is the class that it should be passing to. 这是它应该传递给的类。
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
Here is the class that Monitor inherits: 这是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
Whenever the controller gets called though, looking at the monitor variable in debugger, I see that all the values are set to Nothing. 每当调用控制器时,只要在调试器中查看监视变量,我都会看到所有值都设置为Nothing。
Any idea what could be causing this? 知道是什么原因造成的吗?
Based upon the data you are showing in JSON. 根据您以JSON显示的数据。 You need to set
monitor
您需要设置
monitor
$.ajax({
url: '@Url.Action("submitMonitor", "Home")',
type: 'GET',
contentType: 'application/json',
data: {monitor:data}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.