How do I map paths with Preview 2?

Last post 03-17-2008 4:25 PM by johannes.hiemer. 5 replies.

Sort Posts:

  • How do I map paths with Preview 2?

    03-17-2008, 12:20 PM
    • Member
      7 point Member
    • opt4
    • Member since 02-27-2008, 8:21 PM
    • Posts 14

    Hello,

    How should paths to resources such as scripts, stylesheets, images, etc. be mapped with Preview 2 (IOW how does one resolve URLs with Preview 2)?

    The older information about this seems to be outdated.

    Thanks!

  • Re: How do I map paths with Preview 2?

    03-17-2008, 1:28 PM

     Hi opt4,

    if you want to use the scripts, stylesheets etc. on your whole site then you should use the Site.Master pattern, There you can reference it all from the common content-folder like this:

     

    1    <head runat="server">
    2        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    3        <title>My Sample MVC Application</title>
    4        <link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
    5    </head>
     
    For images in your template you can use the HTML.Helpers provided with MVC 2. This would look likes this:
     
    1    <%=Html.Image(“~/Images/bigwave.jpg”) %><br />
    2    
    3    <%=Html.Image(“~/Images/bigwave.jpg”, “myWave”, new { width = “30px” })%><br />
    Hope this helps.
    Regards Johannes 
     
     
    (If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

    Best Regards,
    Johannes



    http://www.itecon.de
    http://dotnet.johanneshiemer.de
  • Re: How do I map paths with Preview 2?

    03-17-2008, 1:55 PM
    • Member
      7 point Member
    • opt4
    • Member since 02-27-2008, 8:21 PM
    • Posts 14

    Hi Johannes--thanks for your response.

    I agree with your approach, but should have mentioned in my original post that this is a "virtual directory" scenario, and thus the relative path is different between my desktop and the development server.

    I need to reference paths both in my master and view pages, and would prefer to find a common solution for both. A helper method common to scripts, stylesheets, and images would be ideal.

    Unfortunately my app must share with others, so the choice of virtual directory (as well as others decisions like platform, framework and browser) is beyond my control.

  • Re: How do I map paths with Preview 2?

    03-17-2008, 2:24 PM
    Answer
    • Contributor
      4,372 point Contributor
    • tgmdbm
    • Member since 12-17-2007, 2:08 PM
    • Posts 883
    • ASPInsiders
      TrustedFriends-MVPs

    Url.Content( "content/images/logo.gif" ) will get you an absolute url to your resource.

    Html.Image( ... ) will create an app relative src attribute.

     

    In either case, no mater which virtual directory you app is hosted in it will resolve to the correct resource.

    Let me know if this doesn't work for you. 


  • Re: How do I map paths with Preview 2?

    03-17-2008, 2:49 PM
    • Member
      7 point Member
    • opt4
    • Member since 02-27-2008, 8:21 PM
    • Posts 14

    Thanks tg, that's the stuff right there (guess I need to update the dev server with Preview 2 now).

    I was confused by the ResolveUrl discussion.

  • Re: How do I map paths with Preview 2?

    03-17-2008, 4:25 PM

    Hi opt4,

    okay did not think of that problem. You are right. The provided solutions works fine.

     

    Don't forget to mark the topic/question as answered/solved.

    Regards Johannes

    (If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

    Best Regards,
    Johannes



    http://www.itecon.de
    http://dotnet.johanneshiemer.de
Page 1 of 1 (6 items)