ASP.NET MVC4 WebAPI and Posting XML data

albafr

New Member
I'm missing a trick with the new webapi - I'm trying to submit an xml string through a post request and not having much luck.The front end is using jQuery like this:\[code\] $(document = function () { $("#buttonTestAPI").click(function () { var d = " <customer><customer_id>1234</customer_id></customer>"; $.ajax({ type: 'POST', contentType: "text/xml", url: "@Url.Content("~/api/Customer/")", data: d, success: function (result) { var str = result; $("#output").html(str); } }); });});\[/code\]My controller is pretty simple at the moment - just the default for the post action - trying to return what was passed in:\[code\] public string Post(string value) { return value; }\[/code\]However, "value" is repeatedly null. The odd thing is, when I change my data in the jquery to be something like this:\[code\]d = "<customer_id>1234</customer_id>";\[/code\]Then I get "value" in my controller as 1234.How can I get access to the more complex xml string in my controller?
 
Back
Top