0

how many methods for adding style sheets in a page using Asp.net MVC

3
  • We will you don't need to have pls help in the title. It's what we do here =) Commented Feb 21, 2009 at 13:47
  • Another question with "pls help" in the title? Commented Mar 12, 2009 at 6:29
  • pls help ppl write better question titles. By editing their questions. Commented Mar 19, 2009 at 0:06

4 Answers 4

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

Use absolute links to css instead of relative (eg /Content/site.css" instead of "../Content/site.css"). Also you may use Html.Stylesheet("~/Content/site.css") extension (in MvcContrib library) to specify a stylesheet.

Comments

0

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

0

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" /> 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.