ExpansionPanel with nested component (TreeView)

1 Answer 50 Views
ExpansionPanel Template TreeView
Justinas
Top achievements
Rank 1
Iron
Justinas asked on 18 Jan 2025, 02:52 PM | edited on 18 Jan 2025, 02:53 PM

Hello,

I need to display multiple ExpansionPanels with nested TreeViews, however I don't find examples of this, and this code is failing with exception:


@(Html.Kendo().ExpansionPanel()
				.Title(group.Text)
				.Content(@<text>
					@(Html.Kendo().TreeView()
					.Name("tree" + group.Id)
					.CheckboxTemplateId("checkbox-template")
					.Checkboxes(true)
					.BindTo(group.Items))
				</text>)
)

Fails with: 


fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HN9NPOSEKJS4", Request id "0HN9NPOSEKJS4:00000002": An unhandled exception was thrown by the application.
      System.NullReferenceException: Object reference not set to an instance of an object.
         at Kendo.Mvc.UI.WidgetBase.VerifySettings()
         at Kendo.Mvc.UI.WidgetBase.WriteHtml(TextWriter writer)
         at Kendo.Mvc.UI.ExpansionPanel.WriteHtml(TextWriter writer)
         at Kendo.Mvc.UI.WidgetBase.RenderHtml(TextWriter writer)
         at Kendo.Mvc.UI.WidgetBase.ToHtmlString()
         at Kendo.Mvc.UI.Fluent.WidgetBuilderBase`2.ToHtmlString()
         at Kendo.Mvc.UI.Fluent.WidgetBuilderBase`2.WriteTo(TextWriter writer, HtmlEncoder encoder)
         at Microsoft.AspNetCore.Mvc.ViewFeatures.Buffers.ViewBuffer.WriteToAsync(TextWriter writer, HtmlEncoder encoder)
         at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderLayoutAsync(ViewContext context, ViewBufferTextWriter bodyWriter)
         at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderLayoutAsync(ViewContext context, ViewBufferTextWriter bodyWriter)
         at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
         at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable`1 statusCode)
         at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable`1 statusCode)
         at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ActionContext actionContext, IView view, ViewDataDictionary viewData, ITempDataDictionary tempData, String contentType, Nullable`1 statusCode)
         at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result)
         at Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|30_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
      --- End of stack trace from previous location ---
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
      --- End of stack trace from previous location ---
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
         at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|7_0(Endpoint endpoint, Task requestTask, ILogger logger)
         at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
         at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
         at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
         at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
         at Microsoft.WebTools.BrowserLink.Net.BrowserLinkMiddleware.InvokeAsync(HttpContext context)
         at Microsoft.AspNetCore.Watch.BrowserRefresh.BrowserRefreshMiddleware.InvokeAsync(HttpContext context)
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)

Treeview works in itself and if I wrap it in ExpansionPanel raw HTML. 

Is there anyway around it?

Thank you.

1 Answer, 1 is accepted

Sort by
0
Justinas
Top achievements
Rank 1
Iron
answered on 18 Jan 2025, 08:36 PM

Solved it, error was due to missing `.Name()` call on the expansion panel component, this works ok:

				@(Html.Kendo().ExpansionPanel()
					.Title(group.Text)
					.Name("panel" + group.Id)
					.Content(@<text>
						@(Html.Kendo().TreeView()
						.Name("tree" + group.Id)
						.CheckboxTemplateId("checkbox-template")
						.Checkboxes(true)
						.BindTo(group.Items))
					</text>)
				)



Anton Mironov
Telerik team
commented on 20 Jan 2025, 06:41 AM

Hi Justinas,

Thank you for sharing the resolution with the community.

Kind Regards,
Anton Mironov
Tags
ExpansionPanel Template TreeView
Asked by
Justinas
Top achievements
Rank 1
Iron
Answers by
Justinas
Top achievements
Rank 1
Iron
Share this question
or