我在Html视图中显示数据时遇到问题。我创建了web api asp.net mvc项目。在web api控制器中,我们创建了crud方法(get,post,put和delete)。例如,我在web api控制器中有以下方法。在Html视图中不显示数据(仅显示'未定义的数据值)
public IEnumerable<vGeneralLedger> GetAllPosting()
{
try
{
return _db.vGeneralLedgers.ToList();
}
catch (Exception ex)
{
throw;
}
}
该方法将显示从数据库的所有发布。我说'会',因为我不明白在HTML中。在HTML中,我有以下功能:
function GetAllPosting() {
jQuery.support.cors = true;
$.ajax({
url: 'http://localhost:xxxxx/api/GeneralLedgerJournal/',
type: 'GET',
dataType: 'json',
success: function (data) {
WriteResponse(data);
},
error: function (x, y, z) {
alert(x + '\n' + y + '\n' + z);
}
});
}
function WriteResponse(generalLedgerJournals) {
$.each(generalLedgerJournals, function (index, generalLedgerJournal) {
$("#GLJtable").append('<tr><td width="150px">' + generalLedgerJournal.Id +
'</td><td width="150px">' + generalLedgerJournal.NaturalBusinessYearId +
'</td><td width="150px">' + generalLedgerJournal.DocumentTypeId +
'</td>' + '<td width="150px">'
+ generalLedgerJournal.AccountNo + '</td><td width="150px">' + generalLedgerJournal.PostingDate +
'</td><td width="150px">' + generalLedgerJournal.MaturityDate +
'</td><td width="150px">' + generalLedgerJournal.Description +
'</td><td width="150px">' + generalLedgerJournal.TotalDebit +
'</td><td width="150px">' + generalLedgerJournal.TotalCredit +
'</td><td width="150px">' + generalLedgerJournal.Balance + '</td><td width="50px">' + '</td></tr>');
});
}
在浏览器控制台(当我打F12)我有JSON数据如图(链接)显示:
https://www.dropbox.com/s/htn5lav9g12c57r/Json%20Result.jpg?dl=0
但在HTML视图( Cshtml)我总是显示'undefined'的数值数据,如图所示(链接): https://www.dropbox.com/s/oi52caemjlx9ed3/My%20result%20always%20undefined.jpg?dl=0