Passing object to MVC 4 Web API using jQuery AJAX

bashsoft

New Member
I am trying to create a web api that can accept objects as parameters...I started with the simple example posted below, but I get an Internal Server ErrorMy AJAX:\[code\]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); }});\[/code\]In Chrome, it gives me the 500 Internal Server Error when trying to access the url:\[code\]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\[/code\]Did it create the url string incorrectly?My code on the MVC side is very simple:\[code\]public IEnumerable<NTOrder> GetOrders(NTOrder inputOrder){ List<NTOrder> NTOrderList = new List<NTOrder>(); NTOrderList.Add(inputOrder); return NTOrderList;}\[/code\]The class NTOrder is pretty simple, and just contains the attributes used in the original AJAX.
 
Back
Top