正确的方法引用的Javascript在ASP.NET MVC? [英] Correct way to reference Javascript in ASP.NET MVC?
问题描述
什么是引用的Javascript在ASP.NET MVC的正确方法是什么?使用类似../../Scripts/Myscript.js似乎做工精细对于那些传统的{}控制器路由/ {行动} / {ID},但任何东西比这更复杂程度更脆弱。更令人关注的是,理性的绝对引用(/Scripts/Myscript.js)在Visual Studio的智能感知突破
What is the correct way to reference Javascript in ASP.NET MVC? Using something like ../../Scripts/Myscript.js seems to work fine for routes that are the traditional {controller}/{action}/{id}, but are more fragile for anything more or less complex than that. Of greater concern is that the rational absolute reference (/Scripts/Myscript.js) breaks Intellisense in Visual Studio.
你怎么处理呢?
编辑:这显然是在这一点上一个非常古老的问题,但我编辑一提的是在MVC4,所有你需要的是这样的:
This is obviously a very old question at this point, but I'm editing to mention that in MVC4, all you need is this:
src="~/Scripts/Whatever.js"
这足以让剃刀来找出你的意思是,使用根路径。
That's enough for Razor to figure out where you mean, using the root path.
推荐答案
< SCRIPT SRC =<%= Url.Content(〜/脚本/ Myscript.js)%> 类型=文/ JavaScript的>< / SCRIPT>
这篇关于正确的方法引用的Javascript在ASP.NET MVC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!