Telerik MVC Grid. How to bind to an anulable column

advertisements

I have a grid with a column which contains a nullable data

Html.Telerik().Grid(Model)
   .Columns(columns =>
    {
       columns.Add(o => o.Foo);
    }

That works, but shows something like [object Object] on the client. Supposedly it should show Foo.Name, I tried to override Foo's ToString() - didn't work, I tried to change that into columns.Add(o => o.Foo.Name);, but then it doesn't want to render the entire grid. I tried to use columns.Bound(o => o.Foo.Name); - no results. BTW, what's the difference between Add() and Bound() ?


I would use the Template of the column to do this. Here is some code

Html.Telerik().Grid(Model)
   .Columns(columns =>
    {
       columns.Add(o => o.Foo).Template(o =>
       {
          %>
             <%= o.Foo != null ? o.Foo.Name : "" %>
          <%
       })
       .ClientTemplate("<#= Foo != null ? Foo.Name : '' #>");
    }