我有一個搜索頁面,其中頁面的頂部是搜索條件與搜索按鈕。屏幕底部是按下搜索按鈕時的結果。在這種情況下,我有6種不同的搜索條件供用戶輸入。我想將所有的標準綁定到一個類中,所以我的Controller操作可以將Json對象作爲類讀取。使用FireBug我能夠看到我的Json構建正確。使用調試器我知道我的控制器/操作正在被解僱。但是,當我使用Controller/Action中的調試器查看類對象時,所有屬性都爲null或零。JQuery使用Json調用控制器/動作
這是我的控制器...。 的[AcceptVerbs(HttpVerbs.Post)] 公共的ActionResult GetStudentByCritera(StudentSearchCriteraCV性判據) { //獲取數據 計算機[ 「MainData」] = studentBLLHdl.StudentFind(性判據); return View(); }
這裏是JavaScript/JQuery的調用控制器... 功能LoadResultTable(){ // 構建JSON對象發送 VAR dataToSend = 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>