0

How to post xml data (eg: <firstName>Nitesh</firstName>) to asp.net controller using jquery ajax? Note: argument(s) of method in controller must not be the string , it must be XmlDocument or any other class capable of handling xml data only

  • 1
    Do you have any code examples of what you have tried? Also there seem to be quite a few posts related to this. See [this](https://stackoverflow.com/a/36473998/1554860) and [this](https://stackoverflow.com/a/17535912/1554860) and [this](https://stackoverflow.com/a/45188788/1554860) and [this](https://stackoverflow.com/a/16223042/1554860) – james Jul 31 '18 at 14:32
  • JAMEZ.... what you have given, its correct but I want to pass the XML data from jquery ajax(contentType: "text/xml") without any conversion to string, and accepting data in xml format only in controller's method – Nitesh kumar Aug 01 '18 at 04:39
  • what you have tried so far? – Nitin Sawant Aug 01 '18 at 04:58
  • 1) Jquery ajax call = $.ajax({ url: "/Home/GetData1", data: "", type: 'POST', contentType: "text/xml", dataType: "text", success: function () { console.log('success'); }, error: function (xhr, ajaxOptions, thrownError) { console.log(xhr.status); console.log(thrownError); } }); – Nitesh kumar Aug 01 '18 at 05:09
  • 2)Controller's method= [HttpPost] public string GetData1(XmlDocument fc) { try { Console.WriteLine(fc); return "xyz"; } catch(Exception ex) { Console.Write(ex); return ex.ToString(); } } – Nitesh kumar Aug 01 '18 at 05:10

0 Answers0