Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 210
AGuyCalledGerald Avatar asked Oct 20 '22 10:10

AGuyCalledGerald


1 Answers

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>);
like image 91
Mike Debela Avatar answered Nov 03 '22 00:11

Mike Debela