我想清理我的代碼剃刀語法問題
@foreach (System.Data.DataRowView c in (System.Data.DataView)ViewBag.Folders)
{
<tr>
@if ((Boolean)c.Row["VF_Visible"]) {
<td><a href="@Url.Action("Index", "page", new { parent = c.Row["SMF_VF_ID"], granParent = c.Row["VF_Parent_ID"] })">@c.Row["SMF_Name"]</a></td>
} else {
<td class="itemUnVisible"><a href="@Url.Action("Index", "page", new { parent = c.Row["SMF_VF_ID"], granParent = c.Row["VF_Parent_ID"] })">@c.Row["SMF_Name"]</a></td>
}
<td>@Html.ActionLink("Edit", "edit", new { id = c.Row["SMF_VF_ID"] })</td>
<td>@Html.ActionLink("Delete", "Delete", new { id = c.Row["SMF_VF_ID"] })</td>
<td>@Html.ActionLink("Preview", "Preview", new { id = c.Row["SMF_VF_ID"] })</td>
</tr>
}
是內部的,如果被複制的代碼。
當我離開的時候,如果只是沒有標籤和結束標籤的td,它會給我一個錯誤。
@foreach (System.Data.DataRowView c in (System.Data.DataView)ViewBag.Folders)
{
<tr>
@if ((Boolean)c.Row["VF_Visible"]) {
<td>
} else {
<td class="itemUnVisible">
}
<a href="@Url.Action("Index", "page", new { parent = c.Row["SMF_VF_ID"], granParent = c.Row["VF_Parent_ID"] })">@c.Row["SMF_Name"]</a></td>
<td>@Html.ActionLink("Edit", "edit", new { id = c.Row["SMF_VF_ID"] })</td>
<td>@Html.ActionLink("Delete", "Delete", new { id = c.Row["SMF_VF_ID"] })</td>
<td>@Html.ActionLink("Preview", "Preview", new { id = c.Row["SMF_VF_ID"] })</td>
</tr>
}
ugh..code湯。使用ViewModel和顯示模板來擺脫foreach循環。 – RPM1984 2011-05-04 12:22:41