MVC5 relative path not working

993 views Asked by At

I update my web application to MVC5. Since it requires Razor 3.0 then I updated it as well.

Suddenly relative paths are not resolved anymore, in _layout.cshtml a link like this:

<link rel="stylesheet" href="~/Content/main.min.css" />

is ok while rendering the home page http://example.com , but it's not referring the root when rendering a page like this http://example.com/level1/test

The link is resolved as: root/level1/Content/main.min.css

2

There are 2 answers

0
Zirc75 On BEST ANSWER

I found the reason, here's a link that explains it very well: URL rewrite issues with ASP.NET Razor 3

0
aspirant_sensei On

Have you tried using @Url.Content?

e.g

<link rel="stylesheet" href="@Url.Content("~/Content/main.min.css")" />

Or perhaps

        @Styles.Render("~/Content/main.min.css")

replacing the whole < link > tag