Jun 21, 2010, 10:31 AM
Absolute/relative routes in MVC
Hi,
How could I perform something like this in my MVC application:
<script src="<%= Url.Content("~/Scripts/site.js")%>" type="text/javascript"></script>
I want to allow absolutes urls in my application in order to has it working both in development and in an deployment using virtual directories. But when I add this line to my view I have this error:Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %> ).
Source Error:
<TABLE border=0 width="100%" bgColor=#ffffcc>
<TBODY>
<TR>
<TD><CODE>An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.</CODE></TD></TR></TBODY></TABLE>
Stack Trace:
<TABLE border=0 width="100%" bgColor=#ffffcc>
<TBODY>
<TR>
<TD><CODE>[HttpException (0x80004005): The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).]
System.Web.UI.ControlCollection.AddAt(Int32 index, Control child) +8689774
Coolite.Ext.Web.ScriptManager.Page_PreRenderComple te(Object sender, EventArgs e) +328
System.Web.UI.Page.OnPreRenderComplete(EventArgs e) +8872106
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2716
</PRE></CODE></TD></TR></TBODY></TABLE>
<HR SIZE=1>
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
<H1>Server Error in '/' Application.
<HR SIZE=1>
</H1>
<H2>The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %> ).
</H2>