This is strange, I have no clue why this is not working, no matter what I do, I am always end up receiving null for the action method parameter. Why is that not working?
<input type="button" value="Save" onclick="SaveDocument()" />
function SaveDocument() {
var data = "sss";
$.ajax({
url: "/Home/Save",
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: JSON.stringify(data),
success: function (mydata) {
alert("Saved");
},
error: function(error)
{
alert('failed');
alert(error);
}
});
}
</script>
[HttpPost]
public ActionResult Save(string data)
{
return null;
}
JSON.stringify("sss")resolves to""sss""So this might be a problem, because this is not a valid JSON.{ "data": "some string" }