I have a search page where the top of the page is search criteria with a search button. The bottom of the screen is the results from when the search button is pressed. In this case I have 6 different search criteria the user can input. I would like to bundle all the criteria into one class so my Controller action can read the Json object as a class. Using FireBug I am able to see my Json is built correctly. Using the debugger I know that my Controller/Action is getting fired. However when I look at the class object with the debugger in the Controller/Action, all the properties are null or zero.
Controller
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult GetStudentByCritera(StudentSearchCriteraCV critera)
{
// Get the Data
ViewData["MainData"] = studentBLLHdl.StudentFind(critera);
return View();
}
JavaScript/JQuery
<script>
$.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>