在我的MVC 5 Web API应用程序中,我有一个带签名的方法
public HttpResponseMessage PostDefects(int user, string order, string mode, [FromBody]List<Defect> defects)
此 API方法从 jQuery 调用,如下所示
$.ajax({
type: "POST",
url: "api/postdefects/123/456/myMode",
dataType: 'json',
contentType: "application/json",
data: JSON.stringify(priv.DefectList),
success: function () {
alert('REST call OK');
},
error: function() {
alert('REST call not OK')
},
cache: false
});
在 5台计算机上,除了 2台计算机外,这项工作没有任何问题。对于这些计算机中的一台,这个问题得到了自动解决,而没有从我这边做任何事情......另一方面,我仍然有问题,我没有在那里得到解决。
当我从我的html页面调用此API时,我收到200(OK)响应,但在API方法中未收到我的json正文JSON.stringify(priv.DefectList)。在之后检查Fiddler时,我可以清楚地看到POST方法正在接收200(OK)响应,并且正文被发送到API方法。但是在我的API方法中,我没有收到对象。
我的网络浏览器是Google Chrome 42.0.2311.135 m。
任何帮助都会很棒!
这是我的缺陷类
public partial class Defect
{
public int ID { get; set; }
public string order { get; set; }
public string operation { get; set; }
public string part_nbr { get; set; }
public string tool { get; set; }
public string imgName { get; set; }
public Nullable<int> imgWidth { get; set; }
public Nullable<int> imgHeight { get; set; }
public double xPos { get; set; }
public double yPos { get; set; }
public int reason { get; set; }
public string reasonText { get; set; }
public Nullable<System.DateTime> isRepaired { get; set; }
public Nullable<System.DateTime> createdTS { get; set; }
public string severity { get; set; }
public string mode { get; set; }
public string badge_nbr { get; set; }
}
这是传递数据的一个例子
[
{
"order":"F00000021489",
"operation":"0010",
"part_nbr":"1741845",
"reason":"6",
"reasonText":"RWK06 Vosk - poškodenie",
"xPos":417,
"yPos":390,
"imgWidth":880,
"imgHeight":824,
"imgName":"1741845_A.png",
"createdTS":"2015-05-07T08:12:12.109Z",
"tool":"1741845T05",
"mode":"REWORK",
"badge_nbr":"0180371"
}
]