不在 Html 视图中显示数据(仅显示 'undefined' 数据值)

Not display data in Html view (shows only 'undefined' for data value)

我在 Html 视图中显示数据时遇到问题。我创建了 web api asp.net mvc 项目。在网络 api 控制器中,我们创建了 crud 方法(get、post、put 和 delete)。例如,我在网络 api 控制器中有以下方法。

public IEnumerable<vGeneralLedger> GetAllPosting()
        {
            try
            {
                return _db.vGeneralLedgers.ToList();
            }
            catch (Exception ex)
            {

                throw;
            }
        }

该方法将显示数据库中的所有 posting。我说 'would',因为我没有在 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 数据,如图所示 (link):

https://www.dropbox.com/s/htn5lav9g12c57r/Json%20Result.jpg?dl=0

但是在Html视图中(Cshtml)我总是显示'undefined'值数据,如图(link): https://www.dropbox.com/s/oi52caemjlx9ed3/My%20result%20always%20undefined.jpg?dl=0

在我的个人资料 'digging' 之后,我找到了我发布的帖子。 这个问题的答案是(如果我们使用angular),有必要创建一个angular服务(使用$http.get方法)来访问网络服务(web api 或 mvc 控制器)。之后,我们可以创建 angular 控制器并向该控制器注入 angular 服务。我们可以在控制器中创建函数,该函数将从注入的 angular 服务中调用方法。控制器中的作用域对象或数组必须与 html 页中的变量等效。