Reputation: 1476
I am trying to use knockout.js in my MVC 4 (Web Api) project, so I added Knockout.js using Managae NuGet Packages, than I added it to the BundleConfig
bundles.Add(new ScriptBundle("~/bundles/knockout").Include(
"~/Scripts/knockout-{version}.js"));
I added it in my _Layout.cshtml
@Scripts.Render("~/bundles/knockout")
When I tried to use it in my ViewModel.js - ko.applyBindings(new ViewModel());
it didn't recognize it -> the "word" ko wasn't found...I ignored it and continued to write my code but after running it no comment from the knockout.. What am I missing here?
Upvotes: 0
Views: 507
Reputation: 39004
You have not shown your code, but I think the problem is quite easy to explain:
You have to change your code, so that, when you call one of the ko method, ko is already loaded. Two possible options (but there are more):
<head>
section of your layoutcall the ko function from inside the jQuery document ready event, like this:
$(document).ready(function() { // Your ko calls here });
In fact, the second solution wait to execute the code until all the page has been loaded, and is the recommende way to run any script that interacts with the DOM of the page.
Upvotes: 1