Reputation: 13
I want to send a simple string ( which is xml ) to a controller. I don't know why the breakpoint in Visual Studio is not hit.
Here is the jQuery code :
$.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);
}
});
And here is my method in the controller:
[HttpPost]
public ActionResult show(string xml)
{
try
{
ViewBag.xml = xml;
return PartialView("showXML");
}
catch (Exception)
{
return Content("error");
}
}
I have just a 500 error in the console.
Upvotes: 1
Views: 498
Reputation: 40383
The post data isn't properly formatted. Try passing in encodeURIComponent(xmlResult)
instead of just xmlResult
. This will escape out the =
and other characters that won't work properly in a post value.
Upvotes: 0