在 Razor 视图中引用 JavaScript 文件以获取 JavaScript Intellisense
Visual Studio 提供 JavaScript Intellisense。它足够聪明,可以看到您引用母版页中的 JavaScript 文件(例如 jQuery 文件),然后在应用程序的任何视图中提供语句完成。然而,这似乎不适用于 Razor。有没有办法让它与 Razor 一起工作? ASPX 视图引擎提供了这个技巧,例如: <% /* %><% */%>
Visual Studio offers JavaScript Intellisense. It's smart enough to see that you refer to JavaScript files in your master pages (for example jQuery file) and then offers statement completion in any view of the application. However this doesn't seem to work with Razor. Is there a way to get this working with Razor?
ASPX view engine offers this trick for example: <% /* %><script src="~/Scripts/jquery-1.4.1-vsdoc.js"></script><% */ %>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该能够执行以下操作:
这样,当应用程序运行时,代码将永远不会运行,但 VS 不会知道
if (false)
,因此它将解析标记并允许 Intellisense 将其考虑在内。在 Razor 文件中使用 Razor 注释的问题是 VS 会识别它们并完全忽略其中的任何内容。例如,这是行不通的:
You should be able to do something like this:
That way the code will never run when the app runs, but VS won't know about the
if (false)
, so it will parse the<script>
tag and allow Intellisense to take it into account. The problem with using Razor comments in Razor files is that VS will recognize them and completely ignore anything inside them. For example, this won't work:为了防止编译器发出有关无法访问代码的警告,您可以使用编译指示进一步包装它:
To prevent compiler warnings about unreachable code, you can further wrap this with a pragma: