本文介绍了可以在不构建字符串的情况下使用ClientRowTemplate()Kendo UI Grid吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Kendo UI网格中使用ClientRowTemplate给出的示例 HTML字符串

The example given for using ClientRowTemplate in the Kendo UI Grid uses a nasty HTML string

.ClientRowTemplate(
    "<tr><td colspan=\"6\">" +
        "<div class=\"customer-details\">" +
            "<img src=\"" + @Url.Content("~/Content/web/Customers/") + "#=CustomerID#.jpg\"" +
                "alt=\"#=ContactName#\" />" +
            "<h3 class=\"k-widget\">#=ContactName#</h3>" + 
            "<dl>" +
               "<dt>Name:</dt><dd>#=ContactName#</dd>" +
               "<dt>Company:</dt><dd>#=CompanyName#</dd>" + 
               "<dt>Country:</dt><dd>#=Country#</dd>" +
            "</dl>" +
            "<dl >" +
                "<dt>Address:</dt><dd>#=Address#</dd>" +
                "<dt>Phone:</dt><dd>#=Phone#</dd>" +
            "</dl>" +
        "</div>" +
    "</td></tr>"        
)

我当前正在使用部分视图.ClientRowTemplate(Html.Partial("_ClientRowTemplate").ToHtmlString()),但是最好将其包含在同一视图文件中.

I am currently using a partial view .ClientRowTemplate(Html.Partial("_ClientRowTemplate").ToHtmlString()), but it would be nice to have it in the same view file.

是否有内置的方法来使用更好的东西,例如<script id="rowTemplate" type="text/x-kendo-tmpl">块?我仍然想使用Kendo MVC助手而不是JavaScript.

Is there a built-in way to use something a bit nicer like a <script id="rowTemplate" type="text/x-kendo-tmpl"> block? I would still like to use the Kendo MVC helpers and not JavaScript.

推荐答案

查看有关模板化剃刀代表的Haacks博客. http://haacked.com/archive/2011/02/27/templated-razor-delegates.aspx/

Check out Haacks blog on templated razor delegates. http://haacked.com/archive/2011/02/27/templated-razor-delegates.aspx/

基本上,您可以定义一堆剃刀,将其呈现为HTML

Basically you can define a chunk of razor that will be rendered as HTML

定义剃须刀代表

@{
Func<dynamic, object> tableRow = @<tr></tr>;
}

然后执行

.ClientRowTemplate( @tableRow(null).ToString() )

这篇关于可以在不构建字符串的情况下使用ClientRowTemplate()Kendo UI Grid吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 11:40