如何写一个的Razor视图评论? [英] How to write a comment in a Razor view?
问题描述
如何写在MVC视图注释,不会被传递到最终的HTML(即,浏览器,以响应)。一个可以与评论
How to write a comment in a mvc view, that won't be transmitted to the final html (i.e.,to browser, to response). One can make a comment with
<!--<a href="/">My comment</a> -->
但它在浏览器页面的源代码code可见。
But it is visible in the page source code in browser.
是否有可能离开CSHTML文件评论仅供内部使用?
Is it possible to leave comments in cshtml files only for internal use?
推荐答案
的请注意,在一般情况下,IDE就像Visual Studio将标记当前语言的背景下评论,选择你想转成文本一个注释,然后使用 CTRL-K CTRL-C 快捷方式,或者如果您使用ReSharper的/的Intelli-J型快捷键,那么按Ctrl /
。的
Note that in general, IDE's like Visual Studio will markup a comment in the context of the current language, by selecting the text you wish to turn into a comment, and then using the ctrl-k ctrl-c shortcut, or if you are using Resharper / Intelli-J style shortcuts, then Ctrl /
.
的服务器端注释:的
剃须刀.cshtml
@* Comment goes here *@
的.aspx 结果
对于那些寻找老的.aspx
视图(和Asp.Net的WebForms)的服务器端注释语法:
.aspx
For those looking for the older .aspx
view (and Asp.Net WebForms) server side comment syntax:
<%-- Comment goes here --%>
的客户端评论的
HTML注释
<!-- Comment goes here -->
JavaScript注释
// One line Comment goes Here
/* Multiline comment
goes here */
如OP提及,虽然在浏览器上没有显示,将仍可以生成客户端的评论的服务器上的页面/脚本文件,并通过所述网页通过HTTP,这除非除去下载(例如微小),意志的浪费I / O 的,并且因为注释可以由用户通过查看页面源代码或拦截与浏览器的开发工具交通或类似小提琴手或者Wireshark的一个工具查看,可同样的带来安全风险的,因此preference使用在服务器上生成的code服务器端的意见(如MVC观点或.aspx页)。
As OP mentions, although not displayed on the browser, client side comments will still be generated for the page / script file on the server and downloaded by the page over HTTP, which unless removed (e.g. minification), will waste I/O, and, since the comment can be viewed by the user by viewing the page source or intercepting the traffic with the browser's Dev Tools or a tool like Fiddler or Wireshark, can also pose a security risk, hence the preference to use server side comments on server generated code (like MVC views or .aspx pages).
这篇关于如何写一个的Razor视图评论?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!