Hello,
I'm using the Drawer component as a nav bar based on your example in github and it works great except for one thing. One of my pages (components) can accept optional URL parameters, i.e. it has two @page directives. If I supply the URL parameters in the address bar I get an object reference error. I tried adding the parameters to the URL when building the DrawerItem the same way they are in the @page directive but that doesn't work. Can you please show me how to make this work? Thank you.
Drawer-Class:
public class DrawerItem
{
public string Text { get; set; }
public string Icon { get; set; }
public bool Expanded { get; set; }
public int Level { get; set; }
public string Description { get; set; }
public bool OpenPage { get; set; }
public string PageUrl { get; set; }
public bool IsSeparator { get; set; } = false;
public IEnumerable<DrawerItem> Children { get; set; }
}
component with the drawer;
foreach (var item in Mandants)
{
DrawerList.Add(new DrawerItem {Text = item.Bezeichnung, Icon = "user", Level = 1, Description = ".", OpenPage = true, PageUrl = $"KundenPG/{item.MandantId}"});
}
the page itself has also two parameters:
@page "/KundenPG"
@page "/KundenPG/{paramMandant}"
this works perfect in my scenario
regards Matthias
[Parameter]
public string paramMandant { get; set; }
with „how does that value get assigned…“ you ask about the value of item.MandantID? This is a list (generated via an API)
As soon as you assigned the value in $"KundenPG/{item.MandantId}"}); And item.MandantID is 5, the parameter will be:
KundenPG/5
And you can get the value in your Page (in my example KundenPG)
Have a look at the example from Telerik
https://github.com/telerik/blazor-ui/blob/master/drawer/sidenav/Shared/MainLayout.razor
You may need to parse the url in GetCurrentPage() and decide which page and Drawer Item is active including the parameters
But I think this is not a Telerik topic
From the console:
System.NullReferenceException: Object reference not set to an instance of an object.
at VeritivLogistics.Web.Shared.MainLayout.<BuildRenderTree>b__0_5(RenderTreeBuilder __builder6)
at Telerik.Blazor.Components.TelerikRootComponent.<BuildRenderTree>b__26_0(RenderTreeBuilder __builder2)
at Microsoft.AspNetCore.Components.CascadingValue`1.Render(RenderTreeBuilder builder)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch(RenderQueueEntry renderQueueEntry)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()