无法呈现列模板

时间:2012-01-02 09:20:17

标签: .net asp.net-mvc telerik-mvc

使用Telerik Grid for MVC渲染列模板时遇到问题。我目前正在使用上一个版本:2011.3.1115.340与ASP.NET MVC 3(Razor视图引擎)

这是我的视图页面的代码:

@{
    Html.Telerik().Grid<CustomerModel>()
        .Name("CustomersGrid")
        .DataKeys(keys =>
                      {
                          keys.Add(c => c.Id);
                      })
        .ToolBar(commands => commands.Insert().ButtonType(GridButtonType.Text).ImageHtmlAttributes(new {style = "margin-left:0"}))
        .DataBinding(dataBinding =>
                         {
                             dataBinding.Ajax()
                                 .Select("_SelectBinding", "Customers")
                                 .Insert("_InsertBinding", "Customers")
                                 .Update("_SaveBinding", "Customers")
                                 .Delete("_DeleteBinding", "Customers");
                         })
        .Columns(columns =>
                     {
                         columns.Bound(c => c.Id).Width(20).ReadOnly(true);
                         columns.Bound(c => c.Email);
                         columns.Bound(c => c.Lastname);
                         columns.Bound(c => c.Firstname);
                         columns.Bound(c => c.MobilePhone);
                         columns.Bound(c => c.EnterpriseName);
                         columns.Bound(c => c.ManagementComments);
                         columns.Bound(c => c.IsActivated);
                         columns.Template(
                             @<text>
                                  <div>@item.Id</div>
                              </text>
                             ).Title("Premium");
                     })
        .Editable(editing => editing.Mode(GridEditMode.InLine))
        .Pageable()
        .Sortable()
        .ClientEvents(events => events.OnComplete("Grid_onComplete")).Render();
}

我的网格中有模板列“premium”但它仍然是空的:

http://www.imagup.com/data/1140161102.html

我也在没有Render()的情况下进行测试,结果相同:

@(Html.Telerik().Grid<CustomerModel>()
        ... blabla ...
                         columns.Template(
                             @<text>
                                  <div>@item.Id</div>
                              </text>
                             ).Title("Premium");
                     })
        .Editable(editing => editing.Mode(GridEditMode.InLine))
        .Pageable()
        .Sortable()
        .ClientEvents(events => events.OnComplete("Grid_onComplete"))
)

感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

您的网格是ajax绑定,这意味着不应用服务器端模板。请改用ClientTemplate:

columns.Template(@<text>
   <div>@item.Id</div>
</text>)
.ClientTemplate("<div><#= Id #></div>")
.Title("Premium");