This is a migrated thread and some comments may be shown as answers.

MVC Grid Binding a very complex Model object

3 Answers 393 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ian
Top achievements
Rank 2
Ian asked on 16 Aug 2013, 09:21 PM
I have a Model which I bind to:
    @(Html.Kendo().Grid(Model.AccountSummary.ClientAccountSummaries)

I am trying to add all the Account Currencies for each Client into a each cell.

                                  columns.Bound(e => e.Client).Template(@<text>
                                                        @foreach (var account in item.Client.Accounts)
                                                        {
                                                            Html.Raw(account.Currency);
                                                            <br/>
                                                        }
                                                        
                                                    </text>)
                                            .Title("Type");

The code compiles and the objects are correct, but grid shows [object object] instead of "CDN<br>USD<br>EUR" in each cell. See image.

What am I missing here?


3 Answers, 1 is accepted

Sort by
0
Ian
Top achievements
Rank 2
answered on 16 Aug 2013, 10:28 PM
Even if I use a super simple <tetxt> template, like below, it always show "[object Object]" in the field:

                     @{
                        var data = Model.AccountSummary.ClientAccountSummaries;
                    }
                       
                    @(Html.Kendo().Grid(data)
                          .Name("dddd")
                          .Columns(columns =>
                              {
                                  columns.Bound(e => e.Client.UserClientFriendlyName)
                                      .Title("Acct. Name / Num");
                                  columns.Bound(e => e.Client)
                                         .Template(@<text>
                                                        <b>Hi Mom</b>
                                                    </text>)
                                      .Title("Type");
                              }
                          )
                          .DataSource(d => d.Ajax().ServerOperation(false))

                     ) 
0
Ian
Top achievements
Rank 2
answered on 16 Aug 2013, 10:29 PM
Even if I use a super simple [text] template, like below, it always show "[object Object]" in the field:

@{
    var data = Model.AccountSummary.ClientAccountSummaries;
}
    
@(Html.Kendo().Grid(data)
      .Name("dddd")
      .Columns(columns =>
          {
              columns.Bound(e => e.Client.UserClientFriendlyName)
                  .Title("Acct. Name / Num");
              columns.Bound(e => e.Client)
                     .Template(@<text>
                                    <b>Hi Mom</b>
                                </text>)
                  .Title("Type");
          }
      )
      .DataSource(d => d.Ajax().ServerOperation(false))
 
 )
0
Alexander Popov
Telerik team
answered on 20 Aug 2013, 02:00 PM
Hello Ian,


After reviewing the provided code I noticed that Grid uses Ajax binding - as a result only client templates are executed:

  • Define ClientTemplate:
    columns.Bound(p => p.EmployeeList).ClientTemplate("#=generateTemplate(EmployeeList)#");
  • generateTemplate function: 
    function generateTemplate(data) {
     
        var template = "";
        if (data != null) {
                  
            for (var i = 0; i < data.length; i++) {
                template = template + data[i].Name + "<br />";
            }
        }
        return template;
    }
Also I would suggest checking the ClientTemplate method and KendoUI template documentation.

Kind Regards,
Alexander Popov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Ian
Top achievements
Rank 2
Answers by
Ian
Top achievements
Rank 2
Alexander Popov
Telerik team
Share this question
or