I am doing a Tutoring form where a tutor selects from a checkbox a day of the week and from 3 dropdowns a time from and a time until, am/pm time that he can teach at that specific day. I need to save all the selected days and times in the database.
So what I have is this:
[checkbox]Sunday [dropdown]4 - [dropdown]5 [dropdown]am/pm <br />
[checkbox]Monday [dropdown]5 - [dropdown]6 [dropdown] am/pm <br />
and so on...
I am using a hash that uses the day as the key and the times as values like this:
var TutorDays = new Object();
Then I loop through the form to save the values for each key as follows:
var Day; $("input[type=checkbox]").each(function () { Day = $('label[for=' + this.id + ']').html();
TutorDays[Day] = "{" + Day + ":" + $("#ddlTimeFrom" + Day).val() + ":" + $("#ddlTimeTo" + Day).val() + ":" + $("#ddlAmPm" + Day).val() + "}";
});
So the saved value in the key is like this: {Sunday:1:2:pm}
Then I use ajax post and here is where I am stuck. I don't know how to pass the whole hash and then parse it in c# code's we bmethod. If I just put TutorDays["Sunday"] then It send the value of TutorDays["Sunday"] as expected.
Is there an elegant and efficient way to pass the whole collection to the WebMethod and then parse the keys and values in C# code.
Thank you for taking the time to read this.
$.ajax({
type: "POST",
url: 'AddEditItem.aspx/SaveTutorData',
data: "{AccountID:'" + AccountID + "'" + ",SubjectID:'" + SubjectID + "'" + ",SchoolID:'" + SchoolID + "',HourlyRate:'" + HourlyRate + "'" + ",TutorDays:'" + TutorDays["Sunday"] + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert("Saved.");
},
error: function () {
alert("Unexpected error occured");
}
});