小编geo*_*n98的帖子

Javascript和Knockout

我是Javascript和Knockout的新手.我坚持要绑定我的ViewModal.以下是ViewModal和View在同一个Index.chtml文件中时正在运行的代码:

ProfilesViewModel = function () {
    self = this;
    self.ProfileId = ko.observable("");
    self.FirstName = ko.observable("");
    self.LastName = ko.observable("");
    self.Email = ko.observable("");
    self.Image = ko.observable("");
    self.Phone = ko.observable("");

    // Public data properties
    self.Profiles = ko.observableArray([]);

    GetAllProfiles();

    function GetAllProfiles() {
        //  alert("here");
        $.ajax({
            type: "get",
            url: "@Url.Action("getAllProfiles")",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
               self.Profiles(data); //Put the response in ObservableArray
            },
            error: function (error) {
               alert(error.status + "<--and--> " + error.statusText);
            }
        });
    };
}
Run Code Online (Sandbox Code Playgroud)

但当我将我的ViewModal移动到另一个Js文件时,如下 Modal.js代码: …

javascript asp.net-mvc binding knockout.js

1
推荐指数
1
解决办法
221
查看次数

标签 统计

asp.net-mvc ×1

binding ×1

javascript ×1

knockout.js ×1