1

我想向控制器发送一个简单的字符串(即 xml )。我不知道为什么没有命中 Visual Studio 中的断点。

这是jQuery代码:

$.ajax({
            type: "POST",
            url: "BasicWizard/show",
            data: "xml="+xmlResult,
            success: function (data) {
                console.log("Oh yeah !");
            },
            error: function(jqXHR, textStatus, errorThrown) {
                console.log(textStatus, errorThrown);
            }


            });

这是我在控制器中的方法:

    [HttpPost]
    public ActionResult show(string xml)

   {
       try
       {
           ViewBag.xml = xml;
           return PartialView("showXML");
       }
       catch (Exception)
       {
           return Content("error");
       }


    }

我在控制台中只有一个 500 错误。

4

2 回答 2

2

尝试这个 :-

data: "{'xml':'" + xmlResult+ "'}",
于 2013-04-17T13:40:57.973 回答
0

帖子数据格式不正确。尝试传入encodeURIComponent(xmlResult)而不是仅仅传入xmlResult. 这将转义=在 post 值中无法正常工作的字符和其他字符。

于 2013-04-17T13:41:58.963 回答