2014-09-03 53 views
0

我使用VB剃刀模板在下列情況下遇到問題用VB剃刀值作爲一類值:無法在TR

@ModelType IEnumerable(Of TrialLearning.Message) 
@Code 
ViewData("Title") = "Index" 
End Code 

<h2>Index</h2> 

<p> 
    @Html.ActionLink("Create New", "Create") 
</p> 
<table class="table"> 
    <tr> 
     <th>  
      @Html.DisplayNameFor(Function(model) model.MessageTo) 
     </th> 
     <th> 
      @Html.DisplayNameFor(Function(model) model.MessageFrom) 
     </th> 
     <th> 
      @Html.DisplayNameFor(Function(model) model.Message1) 
     </th> 
     <th></th> 
    </tr> 

@For Each item In Model 
    @Code 
     Dim readF As String = "" 
     If item.MessageRead = False Then 
      readF="info" 
     End If 
    End Code 

    <tr class="@readF"> 
    <td> 
     @Html.DisplayFor(Function(modelItem) item.MessageTo) 
    </td> 
    <td> 
     @Html.DisplayFor(Function(modelItem) item.MessageFrom) 
    </td> 
    <td> 
     @Html.DisplayFor(Function(modelItem) item.Message1) 
    </td> 
    <td> 
     @Html.ActionLink("Edit", "Edit", New With {.id = item.MessageID}) | 
     @Html.ActionLink("Details", "Details", New With {.id = item.MessageID}) | 
     @Html.ActionLink("Delete", "Delete", New With {.id = item.MessageID}) 
    </td> 
</tr> 
Next 

</table> 

我使用MVC 5和剃刀3.該代碼的絕大部分是簡單腳手架代碼。我只需要根據item.MessageRead值的值更改<tr>的類名稱。

tr中的類表示「> expected」,</td>表示「標識符預期」,<td>表示「屬性說明符不是完整的語句,請使用行連續將該屬性應用於以下語句。

如果有人也可以指向VB的Razor語法的文檔,也將讚賞。

回答

0

下面將工作得很好。上述代碼的問題是我錯過了<tr>之前的「@」。同樣我也很喜歡三元運算符在代碼方面的工作。

​​

在我發佈論壇尋求幫助之前,可能應該更加關注我的代碼。 :-)