how many methods for adding style sheets in a page using Asp.net MVC
-
We will you don't need to have pls help in the title. It's what we do here =)littlegeek– littlegeek2009-02-21 13:47:51 +00:00Commented Feb 21, 2009 at 13:47
-
Another question with "pls help" in the title?Bob Somers– Bob Somers2009-03-12 06:29:24 +00:00Commented Mar 12, 2009 at 6:29
-
pls help ppl write better question titles. By editing their questions.bzlm– bzlm2009-03-19 00:06:53 +00:00Commented Mar 19, 2009 at 0:06
4 Answers
Wherever you're specifying the CSS for your details page instead of a relative path e.g.
<link href="../../Content/CSS/details.css" rel="stylesheet" type="text/css" />
try using the content helper and specifying a virtual path instead
<link href="<%= Url.Content("~/Content/CSS/details.css") %>" rel="stylesheet" type="text/css" />
It seems that the site is having trouble loading getting to the CSS file based on a relative link.
Comments
Is the problem not getting the right CSS? If so, then I would check your Details.aspx file and make sure the link to the CSS is the right path. Most likely, your Details.aspx file got moved into a new subdirectory or into another directory, thus making the relative paths between the aspx file and the CSS file different.
I would check the page source from the browser and look to see what the path to the CSS file is. The way I would solve the problem would be to modify the aspx file to use a fully-qualified path to the css file. Make sure that works. Then try changing the full path to use relative path.
Comments
I had the same issue when working through an example in an MVC book, it mentioned something about the '~' character only working because the <head> tag has the runat="server" attribute on it. So, I tried adding the runat attribute to the link tag itself, as seen below, and it worked:
<link runat="server" href="~/Content/styles.css" rel="stylesheet" type="text/css" />