Note that there are some explanatory texts on larger screens.

plurals
  1. POknockout not working in MVC4 project
    text
    copied!<p>I have the following in my Index.cshtml file (from the knockout site):</p> <pre><code>&lt;p&gt;First name: &lt;input data-bind="value: firstName" /&gt;&lt;/p&gt; &lt;p&gt;Last name: &lt;input data-bind="value: lastName" /&gt;&lt;/p&gt; &lt;h2&gt;Hello, &lt;span data-bind="text: fullName"&gt; &lt;/span&gt;!&lt;/h2&gt; &lt;script type="text/javascript"&gt; // Here's my data model var ViewModel = function (first, last) { this.firstName = ko.observable(first); this.lastName = ko.observable(last); this.fullName = ko.computed(function () { // Knockout tracks dependencies automatically. It knows that fullName depends on firstName and lastName, because these get called when evaluating fullName. return this.firstName() + " " + this.lastName(); }, this); }; ko.applyBindings(new ViewModel("Planet", "Earth")); // This makes Knockout get to work &lt;/script&gt; </code></pre> <p>My Layout has this line: </p> <pre><code>@Scripts.Render("~/bundles/knockout") </code></pre> <p>Which is configured correctly in bundler config:</p> <pre><code>bundles.Add(new ScriptBundle("~/bundles/knockout").Include( "~/Scripts/Libraries/knockout-2.2.1.js")); </code></pre> <p>Chrome sees the file and VS is giving me intellisense, so I'm not sure what's going on. None of the knockout functions are working. </p> <p>I tested this outside of MVC (just using html/css) and it worked fine. Any idea what's going on?</p> <p>EDIT: I tried using a direct reference without bundler and it still doesn't work: </p> <pre><code>&lt;script type="text/javascript" src="~/Scripts/Libraries/knockout-2.2.1.js"&gt;&lt;/script&gt; </code></pre> <p>I'm getting an error from chrome: </p> <pre><code>Uncaught ReferenceError: ko is not defined </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload