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?
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With