Possible to use ClientRowTemplate() Kendo UI Grid

2019-07-06 05:14发布

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>"        
)

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.

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.

1条回答
放我归山
2楼-- · 2019-07-06 05:49

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

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

Define you razor delegate

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

Then do this

.ClientRowTemplate( @tableRow(null).ToString() )
查看更多
登录 后发表回答