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

5
  • 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 and this and this and this Commented Jul 31, 2018 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 Commented Aug 1, 2018 at 4:39
  • what you have tried so far? Commented Aug 1, 2018 at 4:58
  • 1) Jquery ajax call = $.ajax({ url: "/Home/GetData1", data: "<test></test>", type: 'POST', contentType: "text/xml", dataType: "text", success: function () { console.log('success'); }, error: function (xhr, ajaxOptions, thrownError) { console.log(xhr.status); console.log(thrownError); } }); Commented Aug 1, 2018 at 5: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(); } } Commented Aug 1, 2018 at 5:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.