아약스를 사용하여 컨트롤러 메서드를 호출하려고하는데 내부 서버 오류가 발생합니다.MVC 아약스 호출 컨트롤러 메서드
JQuery와는 다음과 같습니다
function user(id) {
alert(id+" "+$("#comment").val());
var param = {
userId : id,
comments : $("#comment").val()
};
$.ajax({
url: "/Admin/User",
contentType: "application/x-www-form-urlencoded",
type: "POST",
datatype: "json",
data: param,
error: function (xmlHttpRequest, errorText, thrownError) {
alert(xmlHttpRequest+"|"+errorText+"|"+thrownError);
},
success: function (data) {
if (data != null) {
alert("success");
}
}
});
}
컨트롤러는 다음과 같습니다
[HttpPost]
public ActionResult User(int id, string comment)
{
var user = UserModel.GetPerson(id);
user.IsDeleted = true;
UserModel.UpdatePerson(user);
return RedirectToAction("ManageUsers");
}
그것은 코드의 밤은 심지어 컨트롤러에가는 것 같습니다. user(id)
의 첫 번째 알림이 실행 중입니다. 아무도 여기서 무슨 일이 일어나는지 보지 않니?
좋은 캐치! 고맙습니다! – Mike
또는 userId 및 comments props가있는 param으로 C# 클래스를 만드는 경우이 객체를 컨트롤러에 전달할 수 있습니다. –