-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

2

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

That's true.But I tried this. Still it did not work.
can you be more descriptive, didn't work does not help to figure out what is wrong there?
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 ?

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.