的Razor视图引擎怪癖在VB.NET [英] Razor View Engine Quirks in VB.NET
问题描述
我刚刚下载的MVC 3.0 RC,我很高兴能开始使用它,特别是的Razor视图引擎。然而,由于在泥类型的人在这里几棒,我们使用,而不是C#VB.NET卡住了。
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剃刀视图,你可以写code是这样的:
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>
}
剃刀会自动检测到&LT;立GT;
文本是一个HTML标签,将切换出code模式。用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
如果我没有在那里,我得到一个运行时错误。此外,&LT;文本&GT;&LT; /文本方式&gt;
标签似乎不工作
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 @:
.
这篇关于的Razor视图引擎怪癖在VB.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!