3

I have Index.cshtml file and I want to include login.css file there. Index.cshtml lives on Views/Home. I created login.css file in Views/Home/css folder. Here is how I linked it on Index.cshtml:

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

But it doesn't work. When I writes styles inside Index.cshtml, it works perfectly. Where I made a mistake?

0

2 Answers 2

4

Typically you would not put your css in the Views folder. This would belong at the root of the website project(wwwroot). This way you would reference your external styles like this:

<link href="~/css/login.css" rel="stylesheet" type="text/css">
Sign up to request clarification or add additional context in comments.

1 Comment

It is worth nothing that Razor (the view engine) will pick up the ~ and convert it to the virtual directory that the application is running in. E.g. if it runs in / then ~/ becomes /, and if the application lives under /My/Special/Site/ then ~/ becomes /My/Special/Site/.
2

You can juste drags you file css file into yous cshtml file and VS to the work for u

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.