Thursday, June 23, 2011

MVC 3 enable jQuery IntelliSense support

In the Razor view engine, there is no central place to add the reference to the vsdoc file,
instead you need to add this code line to each view separately to enable the IntelliSense
support for jQuery.
 

<!DOCTYPE html>
<
html>
<
head>
<meta charset="utf-8" />
<title>@ViewBag.Title</title>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript">
</
script>
<script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript">
</
script>
</head>
<body>
@RenderBody()

/***** Add this line to your razor page to  enable Visual Studio's IntelliSense support for jQuery *****/

@
if (false) { <script src="~/Scripts/jquery-1.5.1-vsdoc.js" type="text/javascript">
</script> }
//The if-statement prevents the script tag from being rendered into the html 
//source code.

<script type="text/javascript" >
// jquery code here... now it will show intellisence for the jQuery
</script>
</
body>
</
html>

In case of asp.net pages.. add the following code..

<%
if (false)
 
      { %> 
        <script src="~/Scripts/jquery-1.5.1-vsdoc.js" 
                type="text/javascript"></script> 
    <%} %>

No comments :

Post a Comment