我正在尝试通过 AJAX 帖子根据上一个下拉列表的值填充下拉列表,但是,url 没有与控制器中的方法正确连接。在 FireBug 中声明以下错误:
"NetworkError: 500 Internal Server Error - http://localhost:1079/RoundDetail/GetCourses"
这是我的控制器:
public class RoundDetailController : Controller
{
private GolfTrackerEntities2 db = new GolfTrackerEntities2();
public JsonResult GetFacilities(int id)
{
var facilities = db.Facilities.Distinct().ToList();
return Json(facilities, JsonRequestBehavior.AllowGet);
}
}
这是我的javascript:
function changeCourses() {
var val = $(this).val();
$courses = $('#ddlCourses');
$.ajax({
url: "@Url.Action("GetCourses", "RoundDetail") ",
type: "POST",
dataType: 'json',
data: "{ 'facilityId':'" + val + "'}",
contentType: "application/json",
success:
function (msg) {
console.log(msg);
var list = JSON.parse(msg.d);
for (var i = 0; i < list.length; i++) {
courseList += '<option value="' + course.Abbr + '">' + course.Name + '</option>';
}
$courses.html(courseList);
}
});
}