【问题标题】:Razor syntax in helper containing HTML包含 HTML 的帮助程序中的 Razor 语法
【发布时间】:2015-03-30 09:00:57
【问题描述】:

我正在使用 Kendo tabstrip 帮助程序,并试图用 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)。

但是这会产生错误:

重载解析失败,因为无法访问“内容” 使用这些参数调用。

我确信这只是由于我在 Razor 知识方面存在差距,但我很难看到下一步。

【问题讨论】:

    标签: asp.net-mvc vb.net razor kendo-ui


    【解决方案1】:

    我的答案是 C#,但剑道控制是一样的:

    @(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>)
    )
    

    【讨论】:

    • 非常感谢,但恐怕我认为这对我没有帮助。我的理解是,使用 sub() @ 或 sub() @
      是您所说明的 vb.net 语法,但这就是我为产生异常所做的...
    【解决方案2】:

    在与 Telerik 支持人员进行对话后,答案变得显而易见。我使用的 @() 语法在 vb.net 中不起作用,而应将 @Code....End Codesub() @&lt;text&gt; .... &lt;/text&gt; 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 推送到浏览器)。

    瞧!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-17
      • 1970-01-01
      • 1970-01-01
      • 2018-11-06
      • 2011-05-16
      • 2011-04-26
      相关资源
      最近更新 更多