如何在Ajax调用中将XML字符串发布到MVC控制器? [英] How to POST XML string in an ajax call to MVC controller?

查看:71
本文介绍了如何在Ajax调用中将XML字符串发布到MVC控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面给出了一个XML字符串.我正在尝试通过Ajax调用将其发布到MVC控制器.并且MVC控制器仅具有字符串参数.我的ajax代码在下面给出,但是它无法处理请求.如何将XML字符串发送到Controller

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) {

             }
         });

谢谢. -Soumya

Thanks. -Soumya

推荐答案

您正在将ajax调用的type设置为POST,而在url参数中使用的方式是查询字符串针对GET请求完成.

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.

当我们使用GET请求时,将传递并置的值,您需要使用data属性将其传递,然后它将作为POST传递给控制器​​操作.

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) {

         }

     });

希望它对您有帮助.

这篇关于如何在Ajax调用中将XML字符串发布到MVC控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆