Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bind two fields in the client template for a kendo grid column

I get an InvalidOperationException with a message saying:

bound columns require a field or property access expression

My razor markup goes like this:

(@Html.Kendo().Grid<StackInfo>()
            .Columns(col =>
            {
                col.Bound(e => e.FileID).Title("ID");
                col.Bound(e => e.Name).Title("Filename");
                col.Bound(e => e.Status);

                col.Bound(e => new { Status = e.Status, FileID = e.FileID }).ClientTemplate("#if(Status == 'new') {#"
                    + "<a href=\"View?TaskID=#FileID#\">View</a>"
                    + "#} else {#"
                    + "<a href=\"Open?TaskID=#FileID#\">Open</a>"
                    + "#} #").Title(string.Empty);
            })
            .AutoBind(false)
            .DataSource(ds => ds
                .Ajax()
                .Read(r => r.Action("Tasks_Read", "Task"))
                .PageSize(10)
                )
            .Pageable()
            .Name("tasksGrid")
            .Scrollable(k => k.Height(205)))

What I am trying to accomplish is that the grid will show an extra column; it furnishes a link, whose action is actually based on the value in the Status field. Hence I've written my ClientTemplate like so.

However I get an exception at that line. What is the correct way to do this?

like image 858
deostroll Avatar asked Jan 17 '14 09:01

deostroll


1 Answers

I think the problem is in .Bound(e => new { Status = e.Status, FileID = e.FileID }) of your fourth column. Try this code:

columns.Template(@<text></text>)
    .ClientTemplate("#if(Status == 'new') {#"
                + "<a href=\"View?TaskID=#FileID#\">View</a>"
                + "#} else {#"
                + "<a href=\"Open?TaskID=#FileID#\">Open</a>"
                + "#} #").Title(string.Empty);
like image 107
Jarosław Kończak Avatar answered Nov 17 '22 12:11

Jarosław Kończak