tags:

views:

165

answers:

4

All I want to do is to write something like

<%=Html.ScriptInclude("~/Scripts/jquery.1.2.6.js")%>

When I do that I get an error:

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)

I'm using ASP.NET MVC Release Candidate 1.

Is that impossible to accomplish?

+1  A: 

Why don't you just do:

<script src="../../Script/jquery.1.2.6.js" type="text/javascript"></script>
Simucal
@TStamper, if you are using ASP.NET MVC and your .js file is in /Scripts default folder, then it is correct.
Simucal
+2  A: 

No. Not impossible. I do exactly that. Code snippet from a recent project below. What seems to be the problem?

Note that StyleSheet and Javascript are my own extension methods, as is the DatedContent extension on UrlHelper. To get your own extension methods to work you'll need to import the namespace containing them at the top of your page.

<%@ Import Namespace="MvcExtensions" %>

<%= Html.StyleSheet( Url.DatedContent( "~/Content/styles/themes/jquery-ui-theme.css" ) )%> 
<%= Html.StyleSheet( Url.DatedContent( "~/Content/styles/Site.css" ), "all" ) %>
<%= Html.Javascript( Url.Content( "~/Scripts/jquery-1.3.2.min.js" ) ) %>
<%= Html.Javascript( Url.Content( "~/Scripts/ui/ui-all-1.7.1.min.js" ) ) %>
tvanfosson
A: 

Try changing...

<%= Html.ScriptInclude("~/Scripts/jquery.1.2.6.js")%>

...to...

<%# Html.ScriptInclude("~/Scripts/jquery.1.2.6.js")%>

(Changing = to #)

David Kolar
+1  A: 

Put your code inside a <asp:PlaceHolder runat="server"> tag. There was a known bug in RC1 that caused this problem. Check page 23 of the release notes .

I haven't upgraded to 1.0, so I don't know if this was fixed or not.

Ben Robbins