views:

78

answers:

1

I have a master page which references a style in the following manner:

<link rel="stylesheet" type="text/css" href="../../Content/Style.css" /> 

All my pages inherit from this master page. And this works well when the URL is http://www.domain.com/home/details/5, however the URL is http://www.domain.com/home/create, then, of course, Style.css cannot be found because `../../Content/Style.css' resolves to a directory one higher where there is nothing there.

How is this typically handled?

+3  A: 

Use Url.Content("~/Content/Style.css") to resolve the path safely.

"~" means the host. e.g.

<link rel="stylesheet" type="text/css" 
href="<%= Url.Content("~/Content/Style.css") %>" /> 
codemeit
Thanks. This did the trick. I do have a follow-up question ( http://stackoverflow.com/questions/2485988/how-to-handle-css-relative-paths-in-an-asp-net-mvc-application ), if you got the appetite.
AngryHacker