Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Ajax POST解析不正确_C#_Asp.net Mvc_Jquery - Fatal编程技术网

C# Ajax POST解析不正确

C# Ajax POST解析不正确,c#,asp.net-mvc,jquery,C#,Asp.net Mvc,Jquery,我正在尝试使用JQuery-AJAX-Post将数据结构从javascript传递回C。javascript端的结构如下所示: var dt = {}; dt.FailureMode = downtime.general; dt.FailureDetailId = downtime.detail; dt.Start = shared_formatDateWithTime(downtime.startTime); dt.End = shared_formatDateWithTime(downtim

我正在尝试使用JQuery-AJAX-Post将数据结构从javascript传递回C。javascript端的结构如下所示:

var dt = {};
dt.FailureMode = downtime.general;
dt.FailureDetailId = downtime.detail;
dt.Start = shared_formatDateWithTime(downtime.startTime);
dt.End = shared_formatDateWithTime(downtime.endTime);
dt.FailureDescription = downtime.description;
dt.FailureSourceId = downtime.source;
dt.FailureReporterId = downtime.reporter;
dt.DowntimeId = downtime.downtimeId;
dt.EquipmentArray = dtBuildUploadArray(downtime.associatedEquip);
dt.ProcessUnitId = window.downtimeConfig.ProcessUnitId;;

shared_showWorkingWindow();
var url = window.WEBROOT + 'Equipment/_EquipmentScheduleLogDowntime';
$.ajax({
    type: 'POST',
    data:dt,
    url: url,
    async: true
});
var equip = new Object();
equip.EquipmentId = window.downtimeConfig.AssociatedEquipments[i].Id;
equip.EquipmentName = window.downtimeConfig.AssociatedEquipments[i].Name;
if (primary == i) {
    equip.PrimaryCause = 1;
} else {
    equip.PrimaryCause = 0;
}
equip.Affected = 1;
ar[ar.length] = equip;
FailureMode:1
FailureDetailId:1
Start:1/22/2014 5:50 PM
End:1/22/2014 5:50 PM
FailureDescription:
FailureSourceId:1
FailureReporterId:1
DowntimeId:0
EquipmentArray[0][EquipmentId]:1
EquipmentArray[0][EquipmentName]:CR SGS 1
EquipmentArray[0][PrimaryCause]:0
EquipmentArray[0][Affected]:1
EquipmentArray[1][EquipmentId]:2
EquipmentArray[1][EquipmentName]:CR Alkon 1
EquipmentArray[1][PrimaryCause]:0
EquipmentArray[1][Affected]:1
EquipmentArray[2][EquipmentId]:5
EquipmentArray[2][EquipmentName]:CR Block Machine 1
EquipmentArray[2][PrimaryCause]:0
EquipmentArray[2][Affected]:1
ProcessUnitId:1
public void _EquipmentScheduleLogDowntime(ReportedDowntime reportedDowntime)
public class ReportedDowntime : DatabagUtility
{
    public int FailureMode { get; set; }
    public int FailureDetailId { get; set; }
    public DateTime Start { get; set; }
    public DateTime? End { get; set; }
    public string FailureDescription { get; set; }
    public int FailureSourceId { get; set; }
    public int FailureReporterId { get; set; }
    public int DowntimeId { get; set; }
    public string DowntimeColor { get; set; }
    public string FailureSourceDescription { get; set; }
    public string FailureReporterDescription { get; set; }
    public string FailureModeDescription { get; set; }
    public string FailureDetailDescription { get; set; }
    public IEnumerable<AffectedEquipment> Equipments { get; set; }
    public AffectedEquipment[] EquipmentArray { get; set; }
    public int ProcessUnitId { get; set; }
public class AffectedEquipment
{
    public int EquipmentId { get; set; }
    public bool PrimaryCause { get; set; }
    public bool Affected { get; set; }
    public string EquipmentName { get; set; }
}
 $.ajax({
    type: 'POST',
    contentType:'application/json',
    data:JSON.stringify(dt),
    url: url,
    async: true,
});
设备阵列由12个对象组成,如下所示:

var dt = {};
dt.FailureMode = downtime.general;
dt.FailureDetailId = downtime.detail;
dt.Start = shared_formatDateWithTime(downtime.startTime);
dt.End = shared_formatDateWithTime(downtime.endTime);
dt.FailureDescription = downtime.description;
dt.FailureSourceId = downtime.source;
dt.FailureReporterId = downtime.reporter;
dt.DowntimeId = downtime.downtimeId;
dt.EquipmentArray = dtBuildUploadArray(downtime.associatedEquip);
dt.ProcessUnitId = window.downtimeConfig.ProcessUnitId;;

shared_showWorkingWindow();
var url = window.WEBROOT + 'Equipment/_EquipmentScheduleLogDowntime';
$.ajax({
    type: 'POST',
    data:dt,
    url: url,
    async: true
});
var equip = new Object();
equip.EquipmentId = window.downtimeConfig.AssociatedEquipments[i].Id;
equip.EquipmentName = window.downtimeConfig.AssociatedEquipments[i].Name;
if (primary == i) {
    equip.PrimaryCause = 1;
} else {
    equip.PrimaryCause = 0;
}
equip.Affected = 1;
ar[ar.length] = equip;
FailureMode:1
FailureDetailId:1
Start:1/22/2014 5:50 PM
End:1/22/2014 5:50 PM
FailureDescription:
FailureSourceId:1
FailureReporterId:1
DowntimeId:0
EquipmentArray[0][EquipmentId]:1
EquipmentArray[0][EquipmentName]:CR SGS 1
EquipmentArray[0][PrimaryCause]:0
EquipmentArray[0][Affected]:1
EquipmentArray[1][EquipmentId]:2
EquipmentArray[1][EquipmentName]:CR Alkon 1
EquipmentArray[1][PrimaryCause]:0
EquipmentArray[1][Affected]:1
EquipmentArray[2][EquipmentId]:5
EquipmentArray[2][EquipmentName]:CR Block Machine 1
EquipmentArray[2][PrimaryCause]:0
EquipmentArray[2][Affected]:1
ProcessUnitId:1
public void _EquipmentScheduleLogDowntime(ReportedDowntime reportedDowntime)
public class ReportedDowntime : DatabagUtility
{
    public int FailureMode { get; set; }
    public int FailureDetailId { get; set; }
    public DateTime Start { get; set; }
    public DateTime? End { get; set; }
    public string FailureDescription { get; set; }
    public int FailureSourceId { get; set; }
    public int FailureReporterId { get; set; }
    public int DowntimeId { get; set; }
    public string DowntimeColor { get; set; }
    public string FailureSourceDescription { get; set; }
    public string FailureReporterDescription { get; set; }
    public string FailureModeDescription { get; set; }
    public string FailureDetailDescription { get; set; }
    public IEnumerable<AffectedEquipment> Equipments { get; set; }
    public AffectedEquipment[] EquipmentArray { get; set; }
    public int ProcessUnitId { get; set; }
public class AffectedEquipment
{
    public int EquipmentId { get; set; }
    public bool PrimaryCause { get; set; }
    public bool Affected { get; set; }
    public string EquipmentName { get; set; }
}
 $.ajax({
    type: 'POST',
    contentType:'application/json',
    data:JSON.stringify(dt),
    url: url,
    async: true,
});
使用Chrome网络工具,我看到JSON数据如下所示:

var dt = {};
dt.FailureMode = downtime.general;
dt.FailureDetailId = downtime.detail;
dt.Start = shared_formatDateWithTime(downtime.startTime);
dt.End = shared_formatDateWithTime(downtime.endTime);
dt.FailureDescription = downtime.description;
dt.FailureSourceId = downtime.source;
dt.FailureReporterId = downtime.reporter;
dt.DowntimeId = downtime.downtimeId;
dt.EquipmentArray = dtBuildUploadArray(downtime.associatedEquip);
dt.ProcessUnitId = window.downtimeConfig.ProcessUnitId;;

shared_showWorkingWindow();
var url = window.WEBROOT + 'Equipment/_EquipmentScheduleLogDowntime';
$.ajax({
    type: 'POST',
    data:dt,
    url: url,
    async: true
});
var equip = new Object();
equip.EquipmentId = window.downtimeConfig.AssociatedEquipments[i].Id;
equip.EquipmentName = window.downtimeConfig.AssociatedEquipments[i].Name;
if (primary == i) {
    equip.PrimaryCause = 1;
} else {
    equip.PrimaryCause = 0;
}
equip.Affected = 1;
ar[ar.length] = equip;
FailureMode:1
FailureDetailId:1
Start:1/22/2014 5:50 PM
End:1/22/2014 5:50 PM
FailureDescription:
FailureSourceId:1
FailureReporterId:1
DowntimeId:0
EquipmentArray[0][EquipmentId]:1
EquipmentArray[0][EquipmentName]:CR SGS 1
EquipmentArray[0][PrimaryCause]:0
EquipmentArray[0][Affected]:1
EquipmentArray[1][EquipmentId]:2
EquipmentArray[1][EquipmentName]:CR Alkon 1
EquipmentArray[1][PrimaryCause]:0
EquipmentArray[1][Affected]:1
EquipmentArray[2][EquipmentId]:5
EquipmentArray[2][EquipmentName]:CR Block Machine 1
EquipmentArray[2][PrimaryCause]:0
EquipmentArray[2][Affected]:1
ProcessUnitId:1
public void _EquipmentScheduleLogDowntime(ReportedDowntime reportedDowntime)
public class ReportedDowntime : DatabagUtility
{
    public int FailureMode { get; set; }
    public int FailureDetailId { get; set; }
    public DateTime Start { get; set; }
    public DateTime? End { get; set; }
    public string FailureDescription { get; set; }
    public int FailureSourceId { get; set; }
    public int FailureReporterId { get; set; }
    public int DowntimeId { get; set; }
    public string DowntimeColor { get; set; }
    public string FailureSourceDescription { get; set; }
    public string FailureReporterDescription { get; set; }
    public string FailureModeDescription { get; set; }
    public string FailureDetailDescription { get; set; }
    public IEnumerable<AffectedEquipment> Equipments { get; set; }
    public AffectedEquipment[] EquipmentArray { get; set; }
    public int ProcessUnitId { get; set; }
public class AffectedEquipment
{
    public int EquipmentId { get; set; }
    public bool PrimaryCause { get; set; }
    public bool Affected { get; set; }
    public string EquipmentName { get; set; }
}
 $.ajax({
    type: 'POST',
    contentType:'application/json',
    data:JSON.stringify(dt),
    url: url,
    async: true,
});
为了清晰起见,删除了一些数组行

我的控制器行如下所示:

var dt = {};
dt.FailureMode = downtime.general;
dt.FailureDetailId = downtime.detail;
dt.Start = shared_formatDateWithTime(downtime.startTime);
dt.End = shared_formatDateWithTime(downtime.endTime);
dt.FailureDescription = downtime.description;
dt.FailureSourceId = downtime.source;
dt.FailureReporterId = downtime.reporter;
dt.DowntimeId = downtime.downtimeId;
dt.EquipmentArray = dtBuildUploadArray(downtime.associatedEquip);
dt.ProcessUnitId = window.downtimeConfig.ProcessUnitId;;

shared_showWorkingWindow();
var url = window.WEBROOT + 'Equipment/_EquipmentScheduleLogDowntime';
$.ajax({
    type: 'POST',
    data:dt,
    url: url,
    async: true
});
var equip = new Object();
equip.EquipmentId = window.downtimeConfig.AssociatedEquipments[i].Id;
equip.EquipmentName = window.downtimeConfig.AssociatedEquipments[i].Name;
if (primary == i) {
    equip.PrimaryCause = 1;
} else {
    equip.PrimaryCause = 0;
}
equip.Affected = 1;
ar[ar.length] = equip;
FailureMode:1
FailureDetailId:1
Start:1/22/2014 5:50 PM
End:1/22/2014 5:50 PM
FailureDescription:
FailureSourceId:1
FailureReporterId:1
DowntimeId:0
EquipmentArray[0][EquipmentId]:1
EquipmentArray[0][EquipmentName]:CR SGS 1
EquipmentArray[0][PrimaryCause]:0
EquipmentArray[0][Affected]:1
EquipmentArray[1][EquipmentId]:2
EquipmentArray[1][EquipmentName]:CR Alkon 1
EquipmentArray[1][PrimaryCause]:0
EquipmentArray[1][Affected]:1
EquipmentArray[2][EquipmentId]:5
EquipmentArray[2][EquipmentName]:CR Block Machine 1
EquipmentArray[2][PrimaryCause]:0
EquipmentArray[2][Affected]:1
ProcessUnitId:1
public void _EquipmentScheduleLogDowntime(ReportedDowntime reportedDowntime)
public class ReportedDowntime : DatabagUtility
{
    public int FailureMode { get; set; }
    public int FailureDetailId { get; set; }
    public DateTime Start { get; set; }
    public DateTime? End { get; set; }
    public string FailureDescription { get; set; }
    public int FailureSourceId { get; set; }
    public int FailureReporterId { get; set; }
    public int DowntimeId { get; set; }
    public string DowntimeColor { get; set; }
    public string FailureSourceDescription { get; set; }
    public string FailureReporterDescription { get; set; }
    public string FailureModeDescription { get; set; }
    public string FailureDetailDescription { get; set; }
    public IEnumerable<AffectedEquipment> Equipments { get; set; }
    public AffectedEquipment[] EquipmentArray { get; set; }
    public int ProcessUnitId { get; set; }
public class AffectedEquipment
{
    public int EquipmentId { get; set; }
    public bool PrimaryCause { get; set; }
    public bool Affected { get; set; }
    public string EquipmentName { get; set; }
}
 $.ajax({
    type: 'POST',
    contentType:'application/json',
    data:JSON.stringify(dt),
    url: url,
    async: true,
});
我报告的停机时间结构如下所示:

var dt = {};
dt.FailureMode = downtime.general;
dt.FailureDetailId = downtime.detail;
dt.Start = shared_formatDateWithTime(downtime.startTime);
dt.End = shared_formatDateWithTime(downtime.endTime);
dt.FailureDescription = downtime.description;
dt.FailureSourceId = downtime.source;
dt.FailureReporterId = downtime.reporter;
dt.DowntimeId = downtime.downtimeId;
dt.EquipmentArray = dtBuildUploadArray(downtime.associatedEquip);
dt.ProcessUnitId = window.downtimeConfig.ProcessUnitId;;

shared_showWorkingWindow();
var url = window.WEBROOT + 'Equipment/_EquipmentScheduleLogDowntime';
$.ajax({
    type: 'POST',
    data:dt,
    url: url,
    async: true
});
var equip = new Object();
equip.EquipmentId = window.downtimeConfig.AssociatedEquipments[i].Id;
equip.EquipmentName = window.downtimeConfig.AssociatedEquipments[i].Name;
if (primary == i) {
    equip.PrimaryCause = 1;
} else {
    equip.PrimaryCause = 0;
}
equip.Affected = 1;
ar[ar.length] = equip;
FailureMode:1
FailureDetailId:1
Start:1/22/2014 5:50 PM
End:1/22/2014 5:50 PM
FailureDescription:
FailureSourceId:1
FailureReporterId:1
DowntimeId:0
EquipmentArray[0][EquipmentId]:1
EquipmentArray[0][EquipmentName]:CR SGS 1
EquipmentArray[0][PrimaryCause]:0
EquipmentArray[0][Affected]:1
EquipmentArray[1][EquipmentId]:2
EquipmentArray[1][EquipmentName]:CR Alkon 1
EquipmentArray[1][PrimaryCause]:0
EquipmentArray[1][Affected]:1
EquipmentArray[2][EquipmentId]:5
EquipmentArray[2][EquipmentName]:CR Block Machine 1
EquipmentArray[2][PrimaryCause]:0
EquipmentArray[2][Affected]:1
ProcessUnitId:1
public void _EquipmentScheduleLogDowntime(ReportedDowntime reportedDowntime)
public class ReportedDowntime : DatabagUtility
{
    public int FailureMode { get; set; }
    public int FailureDetailId { get; set; }
    public DateTime Start { get; set; }
    public DateTime? End { get; set; }
    public string FailureDescription { get; set; }
    public int FailureSourceId { get; set; }
    public int FailureReporterId { get; set; }
    public int DowntimeId { get; set; }
    public string DowntimeColor { get; set; }
    public string FailureSourceDescription { get; set; }
    public string FailureReporterDescription { get; set; }
    public string FailureModeDescription { get; set; }
    public string FailureDetailDescription { get; set; }
    public IEnumerable<AffectedEquipment> Equipments { get; set; }
    public AffectedEquipment[] EquipmentArray { get; set; }
    public int ProcessUnitId { get; set; }
public class AffectedEquipment
{
    public int EquipmentId { get; set; }
    public bool PrimaryCause { get; set; }
    public bool Affected { get; set; }
    public string EquipmentName { get; set; }
}
 $.ajax({
    type: 'POST',
    contentType:'application/json',
    data:JSON.stringify(dt),
    url: url,
    async: true,
});

当调用控制器行时,我得到报告的停机时间中每个顶级元素的值。我得到一个适当长度的AffectedEquipment数组,但每个元素的值都是0或null(视情况而定)。有人能告诉我为什么子元素没有填充吗?

我找到了这个问题的答案:

我更改了我的帖子语法以包括 contentType:'application/json', 数据:JSON.stringify(dt) 传递JSON而不是本机格式

total子句现在看起来如下所示:

var dt = {};
dt.FailureMode = downtime.general;
dt.FailureDetailId = downtime.detail;
dt.Start = shared_formatDateWithTime(downtime.startTime);
dt.End = shared_formatDateWithTime(downtime.endTime);
dt.FailureDescription = downtime.description;
dt.FailureSourceId = downtime.source;
dt.FailureReporterId = downtime.reporter;
dt.DowntimeId = downtime.downtimeId;
dt.EquipmentArray = dtBuildUploadArray(downtime.associatedEquip);
dt.ProcessUnitId = window.downtimeConfig.ProcessUnitId;;

shared_showWorkingWindow();
var url = window.WEBROOT + 'Equipment/_EquipmentScheduleLogDowntime';
$.ajax({
    type: 'POST',
    data:dt,
    url: url,
    async: true
});
var equip = new Object();
equip.EquipmentId = window.downtimeConfig.AssociatedEquipments[i].Id;
equip.EquipmentName = window.downtimeConfig.AssociatedEquipments[i].Name;
if (primary == i) {
    equip.PrimaryCause = 1;
} else {
    equip.PrimaryCause = 0;
}
equip.Affected = 1;
ar[ar.length] = equip;
FailureMode:1
FailureDetailId:1
Start:1/22/2014 5:50 PM
End:1/22/2014 5:50 PM
FailureDescription:
FailureSourceId:1
FailureReporterId:1
DowntimeId:0
EquipmentArray[0][EquipmentId]:1
EquipmentArray[0][EquipmentName]:CR SGS 1
EquipmentArray[0][PrimaryCause]:0
EquipmentArray[0][Affected]:1
EquipmentArray[1][EquipmentId]:2
EquipmentArray[1][EquipmentName]:CR Alkon 1
EquipmentArray[1][PrimaryCause]:0
EquipmentArray[1][Affected]:1
EquipmentArray[2][EquipmentId]:5
EquipmentArray[2][EquipmentName]:CR Block Machine 1
EquipmentArray[2][PrimaryCause]:0
EquipmentArray[2][Affected]:1
ProcessUnitId:1
public void _EquipmentScheduleLogDowntime(ReportedDowntime reportedDowntime)
public class ReportedDowntime : DatabagUtility
{
    public int FailureMode { get; set; }
    public int FailureDetailId { get; set; }
    public DateTime Start { get; set; }
    public DateTime? End { get; set; }
    public string FailureDescription { get; set; }
    public int FailureSourceId { get; set; }
    public int FailureReporterId { get; set; }
    public int DowntimeId { get; set; }
    public string DowntimeColor { get; set; }
    public string FailureSourceDescription { get; set; }
    public string FailureReporterDescription { get; set; }
    public string FailureModeDescription { get; set; }
    public string FailureDetailDescription { get; set; }
    public IEnumerable<AffectedEquipment> Equipments { get; set; }
    public AffectedEquipment[] EquipmentArray { get; set; }
    public int ProcessUnitId { get; set; }
public class AffectedEquipment
{
    public int EquipmentId { get; set; }
    public bool PrimaryCause { get; set; }
    public bool Affected { get; set; }
    public string EquipmentName { get; set; }
}
 $.ajax({
    type: 'POST',
    contentType:'application/json',
    data:JSON.stringify(dt),
    url: url,
    async: true,
});