我想从 ajax 获取控制器中的值。我在控制器中设置了一个断点,它会中断,但值不存在。我的代码中是否遗漏了某些内容,还是需要更改某些内容?
这是我的控制器代码:
[HttpPost]
public ActionResult SubmitResponse(string responseData)
{
string test = responseData;
return View();
}
这是我的ajax代码:
$( "#dialog-form" ).dialog({
autoOpen: false,
height: 500,
width: 900,
modal: true,
buttons: {
"Submit": function () {
var response = $.trim($('#name').val());
//responseData = JSON.stringify(responseData);
alert('response data = ' + response + '!!!');
//alert('YES');
$.ajax({
url: 'Questions/SubmitResponse',
type: 'POST',
data: JSON.stringify(response),
dataType: 'json',
contentType: 'application/json; charset=utf-8',
success: function(){
alert('success');
},
error: function(){
alert('error buddy');
}
});
},