I had a problem displaying my entire view. (no js error) No matter what, when I go to groceries or at home, both kinds are displayed, and I don’t understand why. Isn't that ko: is it supposed to limit one or the other kind? What am I missing?
Index.cshtml
@section SPAViews {
@Html.Partial("_Home")
@Html.Partial("_Products")
}
@section Scripts{
@Scripts.Render("~/bundles/knockout")
@Scripts.Render("~/bundles/app")
}
_Home.cshtml
...
_Products.cshtml
...
products.viewmodel.js
function ProductsViewModel(app, dataModel) {
var self = this;
self.query = ko.observable();
Sammy(function () {
this.get('#products', function () {
$.ajax({
method: 'get',
url: app.dataModel.productsUrl,
contentType: "application/json; charset=utf-8",
success: function (data) {
console.log(data);
self.query(data.query);
}
});
})
});
return self;
}
app.addViewModel({
name: "Products",
bindingMemberName: "products",
factory: ProductsViewModel
});
home.viewmodel.js
function HomeViewModel(app, dataModel) {
var self = this;
Sammy(function () {
this.get('#home', function () {
console.log('home');
});
this.get('/', function () { this.app.runRoute('get', '#home') });
});
return self;
}
app.addViewModel({
name: "Home",
bindingMemberName: "home",
factory: HomeViewModel
});
Ligaments:
bundles.Add(new ScriptBundle("~/bundles/app").Include(
"~/Scripts/sammy-{version}.js",
"~/Scripts/app/common.js",
"~/Scripts/app/app.datamodel.js",
"~/Scripts/app/app.viewmodel.js",
"~/Scripts/app/home.viewmodel.js",
"~/Scripts/app/products.viewmodel.js",
"~/Scripts/app/_run.js"));
source
share