简体   繁体   中英

Partial View in kendo grid column

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.

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>);

Here's another way to accomplish this.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM