简体   繁体   English

网格中的kendou ClientTemplate无法在asp.net mvc 4中运行

[英]kendoui ClientTemplate in Grid not working in asp.net mvc 4

I have been looking all over for the answer and think I am missing something simple. 我一直在寻找答案,并认为我错过了一些简单的事情。 I have a kendo grid where I want one of the columns to be a link to another page with the id as a route parameter. 我有一个kendo网格,我希望其中一列成为另一个页面的链接,id为路由参数。 However, the value in the column cells are the bound values and are unchanged by my template. 但是,列单元格中的值是绑定值,并且我的模板不会更改。 Any insights to this will be appreciated. 任何见解将不胜感激。

@(Html.Kendo().Grid((IEnumerable<ProviderAccess>)Model.Providers)
.Name("grants-grid")
.Columns(columns =>
{
    columns.Bound(a => a.ProviderName);
    columns.Bound(a => a.HasAccess);
    columns.Bound(a => a.ProviderId).ClientTemplate("#= toggleLink(data) #");
})
.Scrollable()
)

<script>
function toggleLink(access) {
    var action = '@Url.Action("Toggle", "Access")';

    var html = kendo.format("<a href='{0}/{1}'>Toggle...</a>",
        action,
        access.ProviderId
    );

    return html;
}
</script>

ClientTemplate isn't using when Kendo Grid is binded to a dataSource on server side like your code. 当Kendo Grid绑定到服务器端的dataSource(如代码)时,ClientTemplate不会使用。

You should use Template method of columns like below 您应该使用如下列的模板方法

 columns.Template(p => "<a href='..../Toggle/Access/" + p.ProviderId + "'>Click</a>");

dataSource.Server() will let you use a custom.template dataSource.Server()将允许您使用custom.template

dataSource.Ajax() will let you use ClientTemplate dataSource.Ajax()将允许您使用ClientTemplate

Figuring that out was really frustrating... They are not interchangeable one of the other will work depending on ajax or Server 弄清楚它真的令人沮丧......它们是不可互换的,其中一个可以工作,具体取决于ajax或Server

              <%: Html.Kendo().Grid((List<RadCarePlus.V2.Web.Models.GetMeSomeData>) ViewData["Mydata"])
                .Name("Grid")
                .Columns(columns =>
                {
                    columns.Template(c => "<a href='ImplementationDetails?EpisodeID=" + c.EpisodeID + "'>" + c.EpisodeID + "</a>").Title("Testing").Width(140);
                    //columns.Bound(c => c.EpisodeID).Width(140);
                    columns.Bound(c => c.AuthStatus).Width(190);
                    columns.Bound(c => c.CPTCode).Width(100);
                    columns.Bound(c => c.inscarrier).Width(110);
                    columns.Bound(c => c.CreatedOn).Width(160);
                    //columns.Template(c => "<a href='ImplementationDetails?EpisodeID=" + c.EpisodeID + "'>" + c.EpisodeID + "</a>");
                    //columns.Template(c => c.EpisodeID).Title("Testing").ClientTemplate("<a href='ImplementationDetails?EpisodeID=#= EpisodeID#'>#= EpisodeID #</a>");
                })
                .Pageable(pageable=> pageable.ButtonCount(5))
                .Sortable(sortable => sortable.AllowUnsort(false))
                .DataSource(dataSource => dataSource.Server().PageSize(5)
                )

            %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM