我想使用AJAX将简单的字符串值传递给我的控制器。 AJAX到达控制器但给它一个空值。此外,如果我将动词添加到我的控制器,它会给我错误。
控制器:
Public Function SaveSelectedAnswer(ByVal strAnswer As String) As ActionResult
Return Content(" OK ")
End Function
脚本:
var rad = document.frmQuestion.SelectedAnswer;
for (var i = 0; i < rad.length; i++) {
rad[i].onclick = function() {
SendToController(this.value);
};
}
function SendToController(answer) {
$.ajax({
url: "/Students/SaveSelectedAnswer",
type: "GET",
data: answer,
dataType: "text",
contentType: "text/plain; charset=utf-8",
success: function(data) {
alert("From Controller:" + data);
},
error: function() {
alert("Error");
}
});
}