我正在使用 asp mvc,我正在像这样在我的程序的一部分中获取数据
public List<IncidentPerAreaCount> getIncident()
{
int RondeboschCounter = 0;
int ClaremontCounter = 0;
int AthloneCounter = 0;
List<IncidentPerAreaCount> IncidentAreaCount = new List<IncidentPerAreaCount>();
IncidentPerAreaCount Rondebosch = new IncidentPerAreaCount();
IncidentPerAreaCount Claremont = new IncidentPerAreaCount();
IncidentPerAreaCount Athlone = new IncidentPerAreaCount();
List<Report> Reports = GetReports();
for (int i = 0; i < Reports.Count(); i++)
{
if (Reports.AsEnumerable().ElementAt(i).Area == "Rondebosch")
{
RondeboschCounter++;
}
else if (Reports.AsEnumerable().ElementAt(i).Area == "Claremont")
{
ClaremontCounter++;
}
else if (Reports.AsEnumerable().ElementAt(i).Area == "Athlone")
{
AthloneCounter++;
}
}
Rondebosch.AreaName = "Rondebosch";
Rondebosch.NumberOfIncidents = RondeboschCounter;
Claremont.AreaName = "Claremont";
Claremont.NumberOfIncidents = ClaremontCounter;
Athlone.AreaName = "Athlone";
Athlone.NumberOfIncidents = AthloneCounter;
IncidentAreaCount.Add(Rondebosch);
IncidentAreaCount.Add(Claremont);
IncidentAreaCount.Add(Athlone);
return IncidentAreaCount;
}
然后我试图通过 Jquery 获取这个字符串
var Reports = [];
$.ajax({
url: "Home/getIncident",
async: false,
dataType: 'json',
success: function (json) { Reports = json.whatever; }
});
alert(Reports);
然而,警报功能一直是空的(即空文本框),而不是带有数据的 json 格式字符串。
请帮忙...