Partial View in kendo grid column

断了今生、忘了曾经 提交于 2019-12-23 10:53:22

问题


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.


回答1:


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



回答2:


Here's another way to accomplish this.

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


来源:https://stackoverflow.com/questions/30649257/partial-view-in-kendo-grid-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!