MVC3 Razor - 将 JavaScript 和 CSS 文件添加到文档头
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6613628/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MVC3 Razor - Adding JavaScript and CSS files to document head
提问by moefinley
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
我以前用过这个,但我忘记了方法的名称。我猜它一定是 MVC3/Razor 独有的。有没有一种方法可以让你包含一个 JavaScript 或 CSS 文件,然后指定它应该在头部。我记得它是两种不同的方法,类似于以下
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?
它们可能是 HTML 助手,但我在任何地方都找不到对它们的任何引用。我要疯了吗?
采纳答案by Ivan Sokalskiy
Check this question, best answer supposed to do what you need: ASP.Net MVC 3 Razor: Include js file in Head tag
检查这个问题,最好的答案应该做你需要的: ASP.Net MVC 3 Razor: Include js file in Head tag
回答by Jamie Dixon
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