Render MVC Partial with Model inside Kendo MVC Grid

1 Answer 62 Views
Grid
Evgueni
Top achievements
Rank 1
Iron
Evgueni asked on 14 Oct 2022, 01:55 PM

I have a partial MVC view called _user.cshtml that displays some basic information about a user:

@model UserVM
<p>
    <span>Name: </span>@Model.Name
    <span>Email: </span>@Model.Email
</p>

In the parent view I have an MVC Kendo Grid:

@model ImportUsersVM
@(Html.Kendo().Grid(Model.Items)
    .Name("ImportUsers")
        .Columns(columns =>
        {
            columns.Bound(i => i.Status);

            columns.Template(i => Html.RenderPartial("_user", i.Payload));
        })
        .DataSource(dataSource => dataSource
            .Ajax()
            .PageSize(100)
            .ServerOperation(false)
        )
)

The highlighted line above doesn't work -- the user information is not rendered.

How can I include an MVC partial on each row of the grid?

Thank you

 

1 Answer, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 19 Oct 2022, 02:25 PM

Hello Evgueni,

You can use the Template column option when the Grid is configured for server binding, and to display the content of a partial view you should pass Html.Partial, instead of Html.RenderPartial:

columns.Template(i => Html.Partial("_user", i.Payload));

Regards,
Ivan Danchev
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Evgueni
Top achievements
Rank 1
Iron
commented on 19 Oct 2022, 03:00 PM

Ivan, is there a way to use Ajax bindings and use partials with Models? Basically, I want HTML to be generated on the server (using a partial) and then somehow to pass that HTML to the client template, or some other way that's compatible with Ajax configuration. Is that possible? Thanks
Ivan Danchev
Telerik team
commented on 24 Oct 2022, 01:50 PM

Evgueni,

For Ajax binding, you have to use ClientTemplate. See my reply in the other thread you opened: https://www.telerik.com/forums/is-it-possible-to-output-result-of-template-in-clienttemplate
Tags
Grid
Asked by
Evgueni
Top achievements
Rank 1
Iron
Answers by
Ivan Danchev
Telerik team
Share this question
or