我试图使用json在dropdownlist中填充数据,但是当我尝试执行此代码时,它显示错误内部服务器错误
模型
public class Sector
{
public int SectorId{ get; set; }
public int SCode{ get; set; }
public int SectorNep{ get; set; }
public int SectorEng{ get; set; }
}
控制器
public JsonResult Sector()
{
var Sectors = db.Sectors.ToList();
// ViewBag.SelectedSector = new SelectList(Sectors, "SectorId","SCode");
return Json(Sectors, JsonRequestBehavior.AllowGet);
}
视图
@Html.DropDownList("SubSector", new SelectList(string.Empty, "Value", "Text"), "Select Subsector", new { @class = "form-control" })
AJAX
$(document).ready(function () {
$.ajax({
type: "GET",
url: "/Occupation/Sector",
datatype: "Json",
success: function (data) {
$.each(data, function (index, value) {
$('#SelectedSector').append('<option value="' + value.SectorId + '">' + value.SCode + '</option>');
// $("#SelectedSector").append('<option value="' + Sector.Value + '">' + Sector.Text + '</option>'); //
});
}
});
当我在浏览器中跟踪错误时,它会显示错误的内部服务器500错误
它没有输入ajax代码,也没有返回任何值