Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't intellisense work on my ko object?

I'm trying out knockout.js in a test MVC3 project. I have the following structure:

Project Root
  Scripts
    jquery-1.4.4.js
    knockout-1.2.0.debug.js
    etc...
  Views
    Home
      Index.cshtml
    Shared
      _Layout.cshtml
  HTMLPage1.htm

In my _Layout.cshtml file, I have the following script blocks:

<script src="/Scripts/jquery-1.4.4.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery.tmpl.js" type="text/javascript"></script>
<script src="/Scripts/knockout-1.2.0.debug.js" type="text/javascript"></script>

In my Index.cshtml file, I'm trying to use the ko object in my script block. It runs fine, but in the VS designer, I don't get any intellisense on the ko object itself.

If I open up a plain HTML file at the root project level and put a script block in there, I get intellisense on the ko object.

What do I have wrong? Why can't intellisense see the ko object in my .cshtml file?

I note in the debug output in VS, I get the following:

Javascript Intellisense Message: JSIntellisense:Internal/window(18:4) : Function expected
Javascript Intellisense Message: JSIntellisense:Internal/window(19:8) : 'ko' is undefined
Javascript Intellisense Message: JSIntellisense:Internal/window(18:4) : Function expected
Javascript Intellisense Message: JSIntellisense:Internal/window(19:8) : 'ko' is undefined
Javascript Intellisense Message: JSIntellisense:Internal/window(18:4) : Function expected
Javascript Intellisense Message: JSIntellisense:Internal/window(19:8) : 'ko' is undefined
Javascript Intellisense Message: JSIntellisense:Internal/window(18:4) : Function expected
Javascript Intellisense Message: JSIntellisense:Internal/window(19:8) : 'ko' is undefined
etc.

like image 557
Craig Shearer Avatar asked May 02 '11 08:05

Craig Shearer


1 Answers

Ah, figured it out. I need to have my script blocks referencing my .js files in the actual .cshtml file.

As in:

@if (false)
{
    <script src="/Scripts/knockout-1.2.0.debug.js" type="text/javascript"></script>
    <script src="/Scripts/jquery-1.4.4.min.js" type="text/javascript"></script>
    <script src="/Scripts/jquery-ui.js" type="text/javascript"></script>
    <script src="/Scripts/jquery.tmpl.js" type="text/javascript"></script>
    <script src="/Scripts/knockout-1.2.0.debug.js" type="text/javascript"></script>
}

The @if (false) means they don't get included at runtime (and so use the scripts includes from my master .cshtml file).

like image 124
Craig Shearer Avatar answered Sep 23 '22 18:09

Craig Shearer