5
votes

I have an ajax enabled kendo grid with a client template that displays data from the model to which the row is bound. (because of ajax, using columns.Template seems not possible.)

@(Html.Kendo().Grid<Model>()
    .Columns(columns =>
    {
       columns.Bound(x => x.SubModel).ClientTemplate("bla #= SomePropertyOfSubModel # bla")
    })
    .DataSource(dataSource => dataSource.Ajax())

This works basically, but I am not satisfied with the result. For ex., I have problems to make kendo controls in the template work. I would rather hang a partial view in the client template, but did not succeed. The farthest I got was

columns.Bound(x => x.SubModel).ClientTemplate(Html.PartialView("view", //??) //how to bind to SubModel?
.ToHtmlString())

Any help is appreciated.

2

2 Answers

3
votes

I think you need .ToClientTemplate() in your kendo control template,

view.cshtml

@(Html.Kendo().NumericTextBox()
      .Name("NameHere")
      .Min(0)
      .HtmlAttributes(new { style = "width:200px" })
      .ToClientTemplate()                                 
)

And then,

 columns.Bound(c => c.SubModel).ClientTemplate(Html.Partial("view").ToHtmlString());

Edit:

If you want to bind a model to the partial view, you could do

columns.Bound(c => c.SubModel.Property).Template(@<text>Html.Partial("view", item.SubModel)</text>);
0
votes

Here's another way to accomplish this.

 @(Html.PageElement().Kendo().Grid<myModel>()
      .Name("GridName")
      .Columns(col => 
                     Html.RenderPartial("Partials/_myDamnedPartial", col)