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
-
1Do 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 thisjames– james2018-07-31 14:32:01 +00:00Commented 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 methodNitesh kumar– Nitesh kumar2018-08-01 04:39:08 +00:00Commented Aug 1, 2018 at 4:39
-
what you have tried so far?Nitin S– Nitin S2018-08-01 04:58:13 +00:00Commented 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); } });Nitesh kumar– Nitesh kumar2018-08-01 05:09:45 +00:00Commented 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(); } }Nitesh kumar– Nitesh kumar2018-08-01 05:10:37 +00:00Commented Aug 1, 2018 at 5:10
Add a comment
|