페이지 상단이 검색 버튼이있는 검색 기준 인 검색 페이지가 있습니다. 화면 맨 아래는 검색 버튼을 눌렀을 때의 결과입니다. 이 경우 사용자가 입력 할 수있는 6 가지 검색 기준이 있습니다. 컨트롤러 객체가 클래스로 Json 객체를 읽을 수 있도록 모든 조건을 하나의 클래스로 묶고 싶습니다. FireBug를 사용하면 Json이 올바르게 빌드 된 것을 볼 수 있습니다. 디버거를 사용하여 나는 나의 컨트롤러/액션이 해고되고 있음을 안다. 그러나 Controller/Action에서 디버거를 사용하여 클래스 객체를 보면 모든 속성이 null 또는 0입니다.Json을 사용하여 Json을 호출하여 컨트롤러/액션을 호출합니다.
여기 내 컨트롤러입니다 .... [AcceptVerbs (HttpVerbs.Post)] 공개 ActionResult GetStudentByCritera (StudentSearchCriteraCV의 critera) {// 데이터 을 ViewData [ "MainData"] = studentBLLHdl.StudentFind (critera)을 가져 오기; 돌아 가기 View(); } 여기
이 var에 dataToSend을 보내 { //하는 JSON 객체를 구축 ... 기능 LoadResultTable() 컨트롤러를 호출하는 자바 스크립트/JQuery와있다 = BuildJson()
$.ajax({
url: "GetStudentByCritera",
type: 'POST',
data: dataToSend,
dataType: 'json',
contentType: "application/json; charset=utf-8",
beforeSend: ClientSideValidate,
success: function(result)
{
alert(result.Result);
$('#SearchResult').html(result.Result).show();
// UnBlock UI
},
error: function (XMLHttpRequest, textStatus, errorThrown)
{
// UnBlock UI
// not sure how to handel error
alert("error happen when posting to 'GetStudentByCritera'")
// typically only one of textStatus or errorThrown
// will have info
this; // the options for this ajax request
}
});
}
function BuildJson()
{
// building Json
var dataForClass = { "StudentSearchCriteraCV" : [{
"StudLname": $("input[name='StudentSearchCriteraCV.StudLname']").val(),
"StudFname": $("input[name='StudentSearchCriteraCV.StudFname']").val(),
"Ssn": $("input[name='StudentSearchCriteraCV.Ssn']").val(),
"StudId": $("input[name='StudentSearchCriteraCV.StudId']").val(),
"Sex": $("input[name='StudentSearchCriteraCV.Sex']").val(),
"Race": $("input[name='StudentSearchCriteraCV.Race']").val()
}]};
return $.toJSON(dataForClass);
}
function ClientSideValidate()
{
// Block the UI
alert("In the ClientSideValidate");
// if error UNBlock UI
// return true if client side data is good.
return true;
}
</script>