我正在尝试创建一个可以接受对象作为参数的 Web api...我从下面发布的简单示例开始,但出现内部服务器错误
我的 AJAX:
var order = {
"id": 1012345,
"carrier": "works",
"created_at": "works",
"description": "works",
"etd": "works",
"invoice_id": 12,
"origin_id": 13,
"po_number": "101",
"shipped_on": "works",
"status": "works",
"updated_at": "works"
};
$.ajax({
url: "http://localhost:3495/api/NTOrder/",
type: "GET",
data: { inputOrder: order },
beforeSend: function(xhr){
xhr.setRequestHeader('username', 'user4');
xhr.setRequestHeader('password', 'secret');
},
success: function(data) {
alert('Success!' + JSON.stringify(data)); $('.result').html(data);
}
});
在 Chrome 中,它在尝试访问 url 时给了我 500 Internal Server Error:
http://localhost:3495/api/NTOrder/?inputOrder%5Bid%5D=1012345&inputOrder%5Bcarrier%5D=works&inputOrder%5Bcreated_at%5D=works&inputOrder%5Bdescription%5D=works&inputOrder%5Betd%5D=works&inputOrder%5Binvoice_id%5D=12&inputOrder%5Borigin_id%5D=13&inputOrder%5Bpo_number%5D=101&inputOrder%5Bshipped_on%5D=works&inputOrder%5Bstatus%5D=works&inputOrder%5Bupdated_at%5D=works
它是否错误地创建了 url 字符串?
我在 MVC 端的代码非常简单:
public IEnumerable<NTOrder> GetOrders(NTOrder inputOrder)
{
List<NTOrder> NTOrderList = new List<NTOrder>();
NTOrderList.Add(inputOrder);
return NTOrderList;
}
NTOrder 类非常简单,只包含原始 AJAX 中使用的属性。