I have a razor page that shows a navigation menu on the right side of the page with a list of items. Users can change the label of those items from the UI and the label name gets refreshed on the UI, i.e. everywhere except the navigation menu. I can change the label names in the navigation menu as well but only if I reload the entire page. I do not want that as it is slow. Is there any way to reload the navigationmenu razor page without reloading the entire page?
Please find the below navigation razor page and the helper method from where I can update the label using setLabel.
NavMenuTree.razor
<AuthorizeView Context="Home">
<Authorized>
<div class="k-card-header mb-3">
<span class="tb-icon-container">
<TelerikSvgIcon Icon="@SvgIcon.Search" Size="@size" />
<TelerikTextBox Value="@FilteredValue" ValueChanged="@((string input) => ChangeValues(input))" Id="filter-value" Size="@size" Rounded="@size" Placeholder="@MOM.UI.Client.Constants.Common.SearchBox" />
</span>
</div>
<div class="menu">
<TelerikTreeView @ref="treeView" Data="@MenuData" Size="@size" OnItemClick="OnTreeViewItemClick"
SelectionMode="TreeViewSelectionMode.Single"
@bind-SelectedItems="@SelectedItems"
@bind-ExpandedItems="@ExpandedItems">
<TreeViewBindings>
<TreeViewBinding TextField="Text" IconField="Icon" IdField="Id" ParentIdField="ParentId" UrlField="Route">
<ItemTemplate>
@{
MenuItem itm = context as MenuItem;
if (itm?.Type == "Screen")
{
<a href="@itm.Route" class="no-decoration">
@if (!string.IsNullOrEmpty(itm.Icon))
{
<span class="@itm.Icon"></span>
}
@itm.Text
</a>
}
else
{
@if (!string.IsNullOrEmpty(itm?.Icon))
{
<span class="@itm.Icon"></span>
}
@itm?.Text
}
}
</ItemTemplate>
</TreeViewBinding>
</TreeViewBindings>
</TelerikTreeView>
</div>
</Authorized>
</AuthorizeView>
@code {
[CascadingParameter]
public Task<AuthenticationState>? AuthenticationState { get; set; }
[CascadingParameter(Name = "size")]
public string? size { get; set; }
public bool firstTimeLoad = true;
public TelerikTreeView? treeView { get; set; }
private IEnumerable<object>? ExpandedItems { get; set; } = new List<object>();
private IEnumerable<object>? SelectedItems { get; set; } = new List<object>();
private IEnumerable<MenuItem>? MenuData { get; set; }
private IEnumerable<MenuItem>? AllData { get; set; }
public string FilteredValue { get; set; }
public AuthenticationState? authState;
public System.Security.Claims.Claim? authClaim;
public System.Security.Claims.Claim? entityActionClaim;
private ClaimsPrincipal? AuthenticationStateUser { get; set; }
protected override async Task OnParametersSetAsync()
{
try
{
AuthenticationState? authenticationState;
authenticationState = await AuthenticationState;
this.AuthenticationStateUser = authenticationState.User;
if (MenuData == null)
{
List<MenuItem> result = (from Menu in MenuItem.GetMenuItems()
from Perm in AuthenticationStateUser.Claims
where ((Perm.Value.Contains(Menu.AuthorizationKey) && Perm.Type == EntityAction._contextType && Menu.Type == "Screen") ||
(Perm.Value.Contains(Menu.AuthorizationKey) && Perm.Type == Module._contextType && Menu.Type == "Menu"))
orderby Menu.ParentId, Menu.Rank
select Menu).ToList();
result.RemoveAll(x => x.Type == "Menu" && !result.Any(y => y.ParentId == x.Id));
result.Add(
new MenuItem
{
Id = 25,
Text = "Logout",
Icon = @"fa-solid fa-sign-out fa-sm",
Type = "Screen",
HasChildren = false,
level = 1,
Rank = 14,
Route = "logout",
AuthorizationKey = null,
});
MenuData = result.AsEnumerable();
AllData = result.AsEnumerable();
}
}
catch (Exception ex)
{
throw ex;
}
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
try
{
if (treeView != null)
{
if (ExpandedItems?.Count() == 0)
{
if (_navMan.BaseUri != _navMan.Uri)
{
string selectedRoute = _navMan.Uri.Replace(_navMan.BaseUri, "/");
var selectedItem = MenuData?.FirstOrDefault(x => x.Type == "Screen" && selectedRoute.ToLower().Contains(x.Route.ToLower()));
if (selectedItem != null)
{
SelectedItems = new List<object>() { selectedItem };
while (selectedItem != null)
{
ExpandedItems = ExpandedItems.Concat(new[] { MenuData.FirstOrDefault(x => x.Type == "Menu" && x.Id == selectedItem.ParentId) });
selectedItem = MenuData.FirstOrDefault(x => x.Type == "Menu" && x.Id == selectedItem.ParentId);
}
}
}
}
}
}
catch (Exception ex)
{
throw ex;
}
await base.OnAfterRenderAsync(firstRender);
}
protected override void OnInitialized()
{
firstTimeLoad = true;
base.OnInitialized();
}
}
MenuHelper.cs
using MOM.Model.Setup;
namespace MOM.UI.Client.Helper
{
public static class UserLabelHelper
{
private static List<LabelDTO> _labels { get; set; }
public static void SetUserLabel(string type, string label)
{
try
{
if (_labels.Any(x => x.Type == type))
{
_labels.FirstOrDefault(x => x.Type == type).UserLabel = label;
}
}
catch (System.Exception ex)
{
throw ex;
}
}
}
}
Please help me on this.