-1

I have an XML string given below. I am trying to post it to MVC controller through Ajax call.And the MVC controller has a string parameter only. My ajax code is given below.But it is not being able to process the request. How can I send XML string to Controller

var textdata = "<bb>tt</bb><ff>rr</ff>";

         $.ajax({
             url: '/AppVersionProtocolMethod/Test',
             type: 'POST',
             data : { xmlData : textdata},
             success: function (datas) {

             }
         });

Thanks. -Soumya

  • Possible duplicate of [A potentially dangerous Request.QueryString value was detected from the client when sending html markup from jquery post call to asp.net page](https://stackoverflow.com/questions/3885697/a-potentially-dangerous-request-querystring-value-was-detected-from-the-client-w) – Peter B Jul 19 '17 at 11:09
  • You're making a POST - surely the data needs to go in the body of the request? Use `data: { xmlData: textdata }` instead – Rory McCrossan Jul 19 '17 at 11:09

1 Answers1

2

You are setting the type of you ajax call is set to POST while the way you are doing it in the url parameter using query string is done for GET requests.

The concatenated values are passed when we use GET request, you need to pass it using the data property then it will get passed to controller action as POST.

so change your code like below to make it work:

$.ajax({
         url: '/AppVersionProtocolMethod/Test',
         type: 'POST',
         data : { xmlData : textdata}
         success: function (datas) {

         }

     });

Hope it helps you.

Ehsan Sajjad
  • 61,834
  • 16
  • 105
  • 160
  • That's true.But I tried this. Still it did not work. – Soumya Ghosh Jul 19 '17 at 11:19
  • can you be more descriptive, didn't work does not help to figure out what is wrong there? – Ehsan Sajjad Jul 19 '17 at 11:33
  • I tried in the Controller action with an attribute called "ValidateInput(false)". And then it is able to take the XML string. But is that a good workaround or can you provide me with some better workarounds ? – Soumya Ghosh Jul 19 '17 at 11:44