5

I've used this before but i've forgotten the name of the method. I'm guessing it must be exclusive to MVC3/Razor. Is there a method that allows you to include a JavaScript or CSS file and then specify that it should be in the head. I remember it as two different methods similar to the following

IncludeJS("my.js").AtHead();
IncludeCSS("my.css").AtHead();

They might be HTML helpers but I can't find any reference to them anywhere. Am I going mad?

3
  • Why not just put it into the _Layout.cshtml file? with the rest of your script/css includes? Commented Jul 7, 2011 at 16:13
  • 2
    What you're talking about sounds like a custom helper similar to: stackoverflow.com/questions/5110028/… Commented Jul 7, 2011 at 16:13
  • Echo Jamie, just write a custom Html.IncludeJS helper extension. Btw, javascript best practices dictates that you should stick scripts right before </body>. This will allow your content to load faster, though you will have to deal with FOUC potentially. Commented Jul 7, 2011 at 19:36

2 Answers 2

4

Check this question, best answer supposed to do what you need: ASP.Net MVC 3 Razor: Include js file in Head tag

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

1 Comment

That page is helpful for JS files, but it doesn't address CSS files.
1

What you're talking about sounds like a custom helper similar to:

Add CSS or JavaScript files to layout head from views or partial views

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.