Absolute/relative routes in MVC

  1. #1

    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>
  2. #2

    RE: Absolute/relative routes in MVC

    Hi,

    Does the folllowing StackOverflow thread help solve the problem, see


    http://stackoverflow.com/questions/7...tains-code-blo




    Geoffrey McGill
    Founder
  3. #3

    RE: Absolute/relative routes in MVC

    Although I do not like too much include server code, it works.



Similar Threads

  1. Replies: 5
    Last Post: Jul 25, 2011, 6:14 PM
  2. [CLOSED] Window position relative
    By 78fede78 in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Nov 24, 2010, 4:46 PM
  3. Replies: 0
    Last Post: Jul 22, 2010, 1:05 PM
  4. [CLOSED] Error loading pages using relative path
    By flormariafr in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Feb 01, 2010, 9:53 AM
  5. Replies: 6
    Last Post: Oct 02, 2008, 12:38 PM

Posting Permissions