[英]Syntax highlighting of javascript file in an ASP.NET MVC view?
I have an ASP.NET MVC website which has a particular javascript file that needs to be run through the razor parser to render some @Url
values. 我有一个ASP.NET MVC网站,该网站具有特定的javascript文件,该文件需要通过剃须刀解析器运行才能呈现某些
@Url
值。 I have a controller action, named public ActionResult Javascript()
which simply returns javascript.cshtml as a partial view. 我有一个名为
public ActionResult Javascript()
的控制器操作,该操作仅将javascript.cshtml作为部分视图返回。
This all works fine, except that I lose syntax highlighting on the javascript. 一切都很好,除了我在javascript上丢失了语法高亮显示之外。 Is there a way to enable the razor parser on custom file extensions so I can rename my view to javascript.js and get that syntax highlighting back?
有没有一种方法可以对自定义文件扩展名启用razor解析器,以便我可以将视图重命名为javascript.js并重新显示该语法? Failing that, is there any other way I can force the view file to syntax-highlight as javascript when it's not wrapped in
<script>
tags? 失败了,还有什么其他方法可以将视图文件未包装在
<script>
标记中时强制将其作为javascript语法高亮显示?
There are better ways to reference controller actions from Javascript than baking in @Url.Action(...)
calls. 与在
@Url.Action(...)
调用中烘焙相比,从JavaScript中引用控制器动作的方法更好。 For example: 例如:
http://haacked.com/archive/2011/08/18/calling-asp-net-mvc-action-methods-from-javascript.aspx http://haacked.com/archive/2011/08/18/calling-asp-net-mvc-action-methods-from-javascript.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.