包含 HTML 的助手中的 Razor 语法

Razor syntax in helper containing HTML

我正在使用 Kendo tabstrip helper 并试图描述 HTML 中的内容,而不是指向一个单独的 vbHTML 文件:

 @(Html.Kendo().TabStrip() _
.Name("tab2") _
.Items(Function(tabstrip) tabstrip.Add().Text("Project") _
.Selected(True) _
.Content(Sub() @(<div>
                     <table id="SummaryDimPanel" class="table slim">
                           ...table contents...
                     </table>
               </div>)
         End Sub)))

(使用建议的语法 here)。

然而这会产生错误:

Overload resolution failed because no accessible 'content' can be called with these arguments.

我确定这只是因为我对 Razor 的了解存在差距,但我很难看到下一步。

我的答案是针对 C# 但 kendo 控件是相同的:

@(Html.Kendo().Window().Name("MoveItem")
.Title("Move Item")
.Visible(false)
.Modal(true)
.Draggable(false)
.Width(900)
.Content(@<text>
   <div>
     <div class="box-head">
           <h2>Select container where item should be moved to</h2>
     </div>
     <div class="box-content" style="font-size: 8pt">
        @(Html.Kendo().Grid<Container>()
          .Name("CGrid_MoveItem")                                      
          .Columns(columns =>
          {
              columns.Bound(c => c.Barcode).Width(100);
              columns.Bound(c => c.NumberofItems).Title("Count").Width(70);
          })          
          .Selectable(selectable => selectable.Mode(GridSelectionMode.Single))                  
          .DataSource(dataSource => dataSource
              .Ajax()
              .Model(model =>
                {
                    model.Id(a => a.Id);
                    model.Field(a => a.Barcode);    
                })                
              .Read(read => read.Action("Move_Read", "CoAdmin"))
            )
        )
        </div>
    </div>
</text>)
)

在与 Telerik 支持对话后,答案就显而易见了。我使用的 @() 语法在 vb.net 中不起作用,而是 @Code....End Code 应该与 sub() @<text> .... </text> End Sub 结合使用来封装 HTML:

@code
    Html.Kendo().TabStrip() _
    .Name("tab2") _
    .Items(Function(tabstrip) tabstrip.Add().Text("Project") _
    .Selected(True).Content(Sub()@<text>
        <table id="SummaryDimPanel" class="table slim">
              ....table contents...
        </table>
    </text> End Sub)).Render()
End code

(这个特殊的 Kendo 帮助程序需要添加 .Render 方法来实际将 HTML 推送到浏览器)。

瞧!