kendo grid column with conditionally chosen action

不羁岁月 提交于 2020-02-24 05:51:04

问题


Here is what I got:

columns.Bound(t => t.Id)
       .Title("")
       .Template(@<text></text>)
       .ClientTemplate("<a class=\"k-button\" href='" 
            + Url.Action("Edit", "Controller") + "/#=Id#'>Edit</a>")
       .Width(110);

What I need is to pick a specific controller action depending on type of object bound. (different form for e.g. CarEdit when lets say Type==1 and PlaneEdit when Type==2)

I've done similar thing using JS recently (to produce ClientTemplate content) but would greatly appreciate solution without nasty JS.


回答1:


As for now this is my best solution:

columns.Bound(t => t.Id)
       .Title("")
       .Template(@<text></text>)
       .ClientTemplate("#= GetEditTemplate(data)#")
       .Width(110);

function GetEditTemplate(data) {
    var html;

    if (data.Type === 1) {
        html = kendo.format("<a class=\"k-button\" href='" + '@Url.Action("Edit1", "Controller")' + "/{0}" + " '>Edit</a>  ",
                            data.Id
        );
    }
    else {
        html = kendo.format("<a class=\"k-button\" href='" + '@Url.Action("Edit2", "Controller")' + "/{0}" + " '>Edit</a>  ",
                            data.Id
        );
    }

    return html;
}


来源:https://stackoverflow.com/questions/21258083/kendo-grid-column-with-conditionally-chosen-action

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!