VB.NET 中的 Razor 视图引擎怪癖 [英] Razor View Engine Quirks in VB.NET
问题描述
我刚刚下载了 MVC 3.0 RC,我很高兴开始使用它,尤其是 Razor 视图引擎.然而,由于这里有一些泥泞的人,我们被困在使用 VB.NET 而不是 C#.
I just downloaded the MVC 3.0 RC and I'm excited to start using it, especially the Razor view engine. However, due to a few stick in the mud type people here, we are stuck using VB.NET instead of C#.
当我开始尝试时,我注意到了一些怪癖.如果您使用 CSHTML 创建 Razor 视图,您可以编写如下代码:
When I started trying it out, I noticed some quirks. If you are creating a Razor view using CSHTML, you can write code like this:
@foreach(string genreName in Model.Genres)
{
<li>@genreName</li>
}
Razor 将自动检测 文本是一个 HTML 标记,并将切换出代码模式".对于 VB.NET VBHTML 文件,这似乎不起作用.这让我把
@:
关键字放在每一行的前面,就像这样:
Razor will automatically detect that the <li>
text is an HTML tag and will switch out of "code mode". With a VB.NET VBHTML file, this doesn't seem to be working. It's making me put the @:
keyword in front of each line like this:
@For Each genreName As String In Model.Genres
@:<li>@genreName</li>
Next
如果我没有它,我会收到运行时错误.此外,<text></text>
标签似乎不起作用.
If I don't have it there, I get a runtime error. Also, the <text></text>
tags don't seem to work.
有人知道这里发生了什么或者是否有解决方法吗?
Anybody know what's going on here or whether there's a workaround?
推荐答案
我想说 Vb.net 需要它的原因是 vb 允许内联 xml 元素而 c# 不允许.
I would say the reason it's required in Vb.net is vb allows xml elements inline whereas c# does not.
Dim xmlMarkup = <someElement>Values</span>
因此,vb 的自然解析器的行为必须与 c# 不同,因此您必须使用 @
告诉解析器转回 html.您可以使用 @
和 @:
.
Because of this the natural parser for vb must behave differently than c# so you have to tell the parser to escape back to html by using the @
. You can use @
and @:
.
这篇关于VB.NET 中的 Razor 视图引擎怪癖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!