user1245777
user1245777

Reputation: 71

MVC ViewUserControl not retrieving css stylesheets

I have Created New MVC2 ViwUserControl and I have added new css file to ~/Content/Styles folder in my solution explorer. but my user control is not retrieving CSS files

 <link href="~/Content/Styles/demo_page.css" rel="stylesheet" type="text/css" />
        <link href="~/Content/Styles/demo_table.css" rel="stylesheet" type="text/css" />
        <link href="~/Content/Styles/demo_validation.css" rel="stylesheet" type="text/css" />
        <link href="~/Content/Styles/jquery.alerts.css" rel="stylesheet" type="text/css" />
        <link href="~/Content/Styles/jquery-ui.css" rel="stylesheet" type="text/css" />
        <link href="~/Content/Styles/jquery-ui-1.7.2.custom.css" rel="stylesheet" type="text/css" />

any ideas/help appreciated?

when i debug through the firbug i'm seeing 404 not found error for these files

Upvotes: 2

Views: 174

Answers (2)

Alex
Alex

Reputation: 35409

The preceding tilde is throwing your code off ...

Change:

<link href="~/ ...

To:

<link href="/ ...

The tilde ~ is a server-side construct commonly used in ASP.Net WebForms with code like:

<img runat="server" src="~/Images/foo.png" />.

In MVC the standard is to use @Url.Content(" ... "); so:

<link href="@Url.Content("~/Content/Styles/demo_page.css")"
      rel="stylesheet" type="text/css" />

Upvotes: 1

Valamas
Valamas

Reputation: 24729

You cannot use ~/ in html. the only works with server-side function that support that vritual path. Remove ~

Upvotes: 0

Related Questions