在VB ASP.NET MVC Razor中循环收集

use*_*388 4 vb.net asp.net-mvc asp.net-mvc-3

我使用以下Razor脚本循环但它给我以下错误:

@foreach (var item in ViewBag.Articles)
{
    <div>@item.Title</div>
}
Run Code Online (Sandbox Code Playgroud)

错误:

描述:编译服务此请求所需的资源时发生错误.请查看以下特定错误详细信息并相应地修改源代码.

编译器错误消息:BC30451:未声明'foreach'.由于其保护级别,它可能无法访问.

来源错误:

第29行:文章第30行:第31行:@foreach(ViewBag.Articles中的var项)第32行:{第33行:

@(item.index).@ item.model.Description

源文件:C:\ Users\darchual\documents\visual studio 2010\Projects\Blog\Blog\Views\Blog\Details.vbhtml Line:31

它还在我的IDE中说"'foreach'未被声明.由于其保护级别,它可能无法访问."

如何循环收集?谢谢您的帮助.

编辑:

这是整个代码:

@ModelType Blog.Blog

@Code ViewData("Title")= ViewBag.Title结束代码

细节

博客

<div class="display-label">name</div>
<div class="display-field">
    @Html.DisplayFor(Function(model) model.name)
</div>

<div class="display-label">description</div>
<div class="display-field">
    @Html.DisplayFor(Function(model) model.description)
</div>

<div class="display-label">dateCreated</div>
<div class="display-field">
    @Html.DisplayFor(Function(model) model.dateCreated)
</div> </fieldset>
Run Code Online (Sandbox Code Playgroud)

用品

@foreach (var item in ViewBag.Articles)
{
    <div>@item.Title</div>
}
Run Code Online (Sandbox Code Playgroud)

@Html.ActionLink("Edit", "Edit", New With {.id = Model.BlogId}) |
@Html.ActionLink("Back to List", "Index") </p>
Run Code Online (Sandbox Code Playgroud)

这是Blog对象:

Imports System.Data.Entity Imports System.ComponentModel.DataAnnotations

公共课博客

Public Property BlogId() As Integer

Public Property Name() As String
Public Property Description() As String
Public Property DateCreated As Date

Public Overridable Property Articles() As ICollection(Of Article)
Run Code Online (Sandbox Code Playgroud)

结束班

公共类BlogDbContext

Inherits DbContext
Public Property Blogs As DbSet(Of Blog)
Run Code Online (Sandbox Code Playgroud)

结束班

编辑:

终于搞定了.工作代码是:

@For Each item In ViewBag.Articles
    @<div>@item.Title</div>
Next
Run Code Online (Sandbox Code Playgroud)

use*_*388 6

答案是:

@For Each item In ViewBag.Articles
    @<div>@item.Title</div>
Next
Run Code Online (Sandbox Code Playgroud)