CSS3
@font-face rule打破了Razor
section,并显示错误消息:CS0103:当前上下文中不存在“font”字样.它在运行时崩溃.
看起来CSS3 @字符是导致Razor解析器失败的问题.
例:
@section HeadCustomStyleBlock { <style type="text/css"> @font-face { font-family: Gentium; src: url(http://example.com/fonts/Gentium.ttf); } <style> }
对于上下文,@Section HeadCustomStyleBlock正在“布局”页面的< head>元件.
解决方法
根据ScottGu的博客:
In cases where the content is valid as code as well (and you want to
treat it as content),you can explicitly escape out @ characters by
typing @@.
http://weblogs.asp.net/scottgu/archive/2010/07/02/introducing-razor.aspx