Robot
December 5, 2022, 1:18pm
1
Hello again,
In my project, I created RadzenTabsItems based on VendorId of order details. I want to get the active/selected tab VendorId so that I can pass it to a method and use it. Any ideas on how I can solve this?
...
<RadzenTabs>
<Tabs>
@{
var detailVendorId = 0;
}
@foreach (var detail in orderDetails)
{
@if (detailVendorId != detail.VendorId)
{
<RadzenTabsItem Text="@detail.Vendor.Name">
...
enchev
December 5, 2022, 1:23pm
2
You will need some dictionary where you can access value by tab index. You can also bind SelectedIndex and use it to get desired value from the dictionary:
1 Like
Robot
December 6, 2022, 6:05am
3
Thank you @enchev . I used the dictionary as you suggested and it works but why it renders twice when the page loads? It gets my data doubled.
The vendors dictionary:
Here is how I added the dictionary:
...
<RadzenTabs @bind-SelectedIndex=@_selectedTab Change=@OnChange>
<Tabs>
@{
var detailVendorId = 0;
}
@foreach (var detail in orderDetails)
{
@if (detailVendorId != detail.VendorId)
{
<RadzenTabsItem Text="@detail.Vendor.Name">
...
</RadzenTabsItem>
vendors.Add(count, detail.VendorId);
count++;
}
int _selectedTab = 0;
IDictionary<int, int> vendors = new Dictionary<int, int>();
int count = 0;
void OnChange(int index)
{
_selectedTab = index;
}
enchev
December 6, 2022, 6:37am
4
Robot:
why it renders twice
Iām afraid that I cannot comment since I know nothing about your application. Maybe you have server prerender:
Whatever is causing this you can simply check if the key is already present before adding.
1 Like