0
我是ASP.NET MVC的新手。我正在VS2012中使用MVC4。我已經通過身份證得到所有工作正常。當我更改我的ajax代碼中的http請求時,發現它發生500錯誤。ASP.NET MVC4得到正常工作後返回500
所以問題 1 - 如何調試這種問題 2 - 爲什麼會發生在這個特定的實例
我敢肯定,這已是與我不理解,我什麼假設在路由代碼
我認爲的代碼,包括是顯著
//the controller method
[System.Web.Mvc.HttpPost]
public void PostPatientAppointment(PatientAppointment patientAppointment)
{
init();
updatePatientAppointmentList();
foreach (PatientAppointment existingPatientAppointment in patientAppointments)
{
if (patientAppointmentConflict(existingPatientAppointment, patientAppointment))
{
throw new HttpException(409, "Conflict");
}
}
//return patientAppointment;
}
function onMouseUp(evt) {
rect = null;
mouseDown = false;
//check for conflicting appointments
//do the xhr request
//cycle through appointments looking for conflicts
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
//open Dojo modal dialogue
alert("will open dialogue");
}
else if(xmlhttp.status == 409)
{
alert("There is a conflict with that patient appointment");
}
alert("hmm - status was: " + xmlhttp.status);
}
}
var patientAppointment = "{'identity':-1,'doctorId':-1,'patientId':-1,'patientName':null,'startTime':-1, 'endTime':-1,'location':null,'reason':null,'note':null,'recurrenceId':0,'appointmentTypeId':0,'patientShowedUp':false,'confirmed':false,'fullDayEvent':false}";
xmlhttp.open("POST", "/api/PatientAppointment/", true);
xmlhttp.send(patientAppointment);
}
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional}
);
}
}