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?

Nate
  • 30,286
  • 23
  • 113
  • 184
moefinley
  • 1,248
  • 1
  • 13
  • 26
  • Why not just put it into the _Layout.cshtml file? with the rest of your script/css includes? – Bob. Jul 07 '11 at 16:13
  • 2
    What you're talking about sounds like a custom helper similar to: http://stackoverflow.com/questions/5110028/add-css-or-js-files-to-layout-head-from-views-or-partial-views – Jamie Dixon Jul 07 '11 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

    . This will allow your content to load faster, though you will have to deal with FOUC potentially.

    – Milimetric Jul 07 '11 at 19:36

2 Answers2

4

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

Community
  • 1
  • 1
Ivan Sokalskiy
  • 812
  • 7
  • 14
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

Community
  • 1
  • 1
Jamie Dixon
  • 53,019
  • 19
  • 125
  • 162