Is it possible to output result of Template in ClientTemplate

1 Answer 79 Views
Grid
Evgueni
Top achievements
Rank 1
Iron
Evgueni asked on 14 Oct 2022, 03:06 PM

I have a grid that I want to be an Ajax grid (not Server) but I need to render one of the cells using ASP.NET MVC partials. Looks somewhat like this:


@(Html.Kendo().Grid(Model.Items)
            .Name("items")
            .Columns(columns =>
            {
                columns.Bound(p => p.Payload).Template(@<text>
                    @Html.Partial(item.ItemUI, item.Payload)
                </text>).ClientTemplate("@output");
            })
    .DataSource(dataSource => dataSource
        .Ajax()
    )
)

Is that possible to instruct Kendo to output the result of a call to Template() in ClientTemplate()? In the example above, is there some magic keyword I can use instead of the highlighted @output to say "output whatever was generated on the server side here?"

Thanks

Evgueni
Top achievements
Rank 1
Iron
commented on 18 Oct 2022, 01:22 PM

Is anybody on the Telerik side monitoring these forums?

Out of 5 questions I posted over the last 6 month, only 1 had an answer from Telerik.  A pretty bad record as far as forum responsiveness goes.

Is it better to post on Stackoverflow? Or is the issue that, practically speaking, there is no real free support for Kendo UI?

1 Answer, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 19 Oct 2022, 03:04 PM

Hello Evgueni,

If you are using ajax binding, i.e. the Grid is populated by a call to a controller actions as shown below:

@(Html.Kendo().Grid<OrderViewModel>()
		.Name("items")
		.DataSource(dataSource => dataSource
			.Ajax()
			.PageSize(20)
			.Read(read => read.Action("Orders_Read", "Home"))
		)
		//...

then you can only use the column's ClientTemplate option. The Template option is used in server binding scenarios.

So displaying the content of a partial view with the ClientTemplate would look like this:

columns.Bound(p => p.Payload).ClientTemplate(Html.Partial("MyPartialName").ToHtmlString());

As for your second question, we do monitor the forums, but we haven't committed to answering every question posted on the forums. The community however is free to participate in the forum discussions. As for providing support, we have a ticketing system, where license holders can submit support-related questions.

Regards,
Ivan Danchev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

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

Ivan, thanks for your answer.

columns.Bound(p => p.Payload).ClientTemplate(Html.Partial("MyPartialName").ToHtmlString());

Is there any way to pass the Model, p.Payload, to the partial here?

Ivan Danchev
Telerik team
commented on 24 Oct 2022, 01:49 PM

Evgueni,

You can do this:

columns.Bound(p => p.Payload).ClientTemplate(Html.Partial("MyPartialName", new ViewDataDictionary {{ "param1", "#= Payload#" }}).ToHtmlString());

And in the partial you can access the parameter:

<p>@ViewBag.param1</p>

Evgueni
Top achievements
Rank 1
Iron
commented on 27 Oct 2022, 01:51 PM

Ivan, thanks for your answer, but when I use your approach, this is what I get in the partial:

And that makes sense since the evaluation of Html.Partial happens at the server time. What's missing is access to the column context variable (p => p.Payload in this case) inside ClientTemplate. I understand that ClientTemplate has its own client-side system for accessing the column context, but before we get to the client, it'd be very useful to have access to the column context inside ClientTemplate in order to pre-generate the HTML.

Thanks

Ivan Danchev
Telerik team
commented on 31 Oct 2022, 02:01 PM

Evgueni,

Something must be different in your case, because I am able to get the value in the ClientTemplate and display it in the partial view. See the attached sample project. The last column in the Grid shows the content of the partial view.

 

 

Tags
Grid
Asked by
Evgueni
Top achievements
Rank 1
Iron
Answers by
Ivan Danchev
Telerik team
Share this question
or