I am trying to get MultiSelect Dropdown filled with Table Entries and then to populate some elements in already selected based on result from another table.
For Example:
BusinessType Table:
1. Salons
2. Doctors
3. Dentists
4. Fitness Centers
CompanyBusinessType Table will contain CompanyID, BusinessTypeID from above Table (for example ABC Company has an ID = 1):
1 -> 1
means this company is a BusinessType of Salon.
I am trying to produce profile page of this company where if there have selected Salon already so it should be coming as selected in Dropdown when we will load this page.
VIEWMODEL:
public class BusinessTypeViewModel
{
public int Id { get; set; }
public string BusinessTypeName { get; set; }
}
CONTROL:
DataSource="businessTypeViewModel" CssClass="text-custom2" AllowFiltering="true" AllowCustomValue="true" Value="@businessTypes" MaximumSelectionLength="@MaxSelectionBtype">
BASE CODE:
public List businessTypes = new List();
public void OnTagging(TaggingEventArgs args)
{
System.Diagnostics.Debug.WriteLine($"OnTagging() -- businessTypes: {string.Join(',', businessTypes)}");
}
protected override async Task OnInitializedAsync()
{
try
{
Globals.businessProfileViewModel = await GetBusinessProfileData();
Globals.businessTypeViewModel = await GetBusinessTypes();
var cbt = Globals.businessProfileViewModel.businessTypes.ToList();
businessTypes.Add(cbt.Select(s => s.BusinessTypeNameEn).FirstOrDefault());
}
catch (Exception ex)
{
Console.WriteLine("Error in OnInit: " + ex.Message);
}
If I change Id from int to string then it works but i cannot change value in MultiSelect, it always remain one assigned by OnInitializedAsync method
businessTypes.Add(cbt.Select(s => s.BusinessTypeName).FirstOrDefault());
its "Salon"
Can you help me resolve this issue ?
Thank you