[英]Razor view with JavaScript only
Due to some limitations I'm ashamed to talk about I need to be able to have a Razor template with just JavaScript inside. 由于某些限制,让我感到羞耻的是,我需要能够拥有仅包含JavaScript的Razor模板。 This is not a problem and it works - everything is rendered properly.
这不是问题,它可以正常工作-一切都正确呈现。 However inside Visual Studio the code is not 'treated' as JavaScript - syntax highlighting, navigation, formatting doesn't work.
但是,在Visual Studio中,代码未像JavaScript一样被“对待”-语法高亮显示,导航和格式设置不起作用。 Even worse - pressing enter causes Visual Studio to freeze for 2-3 seconds and the code to be formatted according to the rules for some other language (most likely HTML).
更糟糕的是,按Enter键会使Visual Studio冻结2-3秒,并根据某些其他语言(很可能是HTML)的规则来格式化代码。
Is there any way to hint Visual Studio to treat the whole content in the cshtml file as JavaScript ? 有什么方法可以暗示Visual Studio将cshtml文件中的全部内容视为JavaScript?
You could trick VS into thinking it's in a script block. 您可以欺骗VS使其认为它在脚本块中。
Just add // <script>
and // </script>
to the top & bottom of the file. 只需将
// <script>
和// </script>
到文件的顶部和底部。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.