C#コードでJQuery Ajax関数とWebMethodを使用して、Ajax経由でデータベースにデータを送信しようとしています。しかし、それは機能していません。何か案は?
$(function() {
$('#Add').click(function() {
var $dialog = $('<div id="MyDialog"></div').appendTo('body')
.load("../Pop-up.aspx #pop-up", createDatePicker)
.dialog({
position: 'center',
width: 550,
buttons: {
"OK": function() {
var jname = $('#name').val();
var jbirthday = $('#datepicker').val();
var jgender = $('input:radio[name=Gender]:checked').val();
var jcourseId = $('#DropDownList1').val();
var myjson = {
name: jname,
birthday: jbirthday,
gender: jgender,
courseId: jcourseId
};
$.ajax({
type: "post",
contentType: "application/json;charset=utf-8",
dataType: "json",
url: "Manage.aspx/AddStudent",
data: $.toJSON(myjson)
});
},
"Cancel": function() {
$(this).dialog('close');
}
}
});
return false;
});
});
これが私のWebメソッドです
[WebMethod]
public static void AddStudent(string birthday,string name,string gender,string courseId)
{
var repository = new StudentRepository();
var student = new Student
{
Birthday = Convert.ToDateTime(birthday),
Name = name,
Gender = gender,
Course_ID = Convert.ToInt32(courseId)
};
repository.InsertStudent(student);
repository.Save();
}