vb Razor语法

时间:2013-06-13 05:01:58

标签: asp.net-mvc razor

我是razor语法的新手,我正努力在代码中正确地逃回html。

这是一个我无法工作的例子

@For Each item In Model
Dim currentItem = item
@<tr>

    <td>
        <video controls poster="@currentItem.ImageName + ".jpg" width="320" height="240">
        <source type="video/flv" src="@currentItem.VideoName + ".flv"">
        </video>
    </td>
    <td>
        @Html.DisplayFor(Function(modelItem) currentItem.Id)
    </td>

    <td>
        @Html.DisplayFor(Function(modelItem) currentItem.Name)
    </td>


 </tr>
Next

我尝试过使用和@:。但是剃刀语法一直在抱怨。非常感谢修复我的代码并解释新代码的工作原理。

干杯!

1 个答案:

答案 0 :(得分:0)

你几乎是对的。唯一的问题是路径的定义。

您基本需要的是以下内容:

<video poster="[image name].jpg" ...>

其中[image name]替换为正确的值。所以你需要@currentItem.ImageName。那是正确的。您可以使用空格结束此表达式。但是,这会将空间添加到输出中,这在此不需要。相反,您可以使用括号来定义表达式的结尾:@(currentItem.ImageName)

所以你的定义是:

<video controls poster="@(currentItem.Day).jpg" width="320" height="240">
    <source type="video/flv" src="@(currentItem.Month).flv">
相关问题