eKek0
eKek0

Reputation: 23329

Is really impossible to write code in an mvc master page?

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?

Upvotes: 0

Views: 252

Answers (4)

David Kolar
David Kolar

Reputation: 3485

Try changing...

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

...to...

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

(Changing = to #)

Upvotes: 0

Ben Robbins
Ben Robbins

Reputation: 2630

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.

Upvotes: 1

mmcdole
mmcdole

Reputation: 92885

Why don't you just do:

<script src="../../Script/jquery.1.2.6.js" type="text/javascript"></script>

Upvotes: 1

tvanfosson
tvanfosson

Reputation: 532755

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" ) ) %>

Upvotes: 2

Related Questions