我是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代码: …