Ulid use on Tvalue dont valorize the result var
I have an object that contain some data to show and a Ulid as ID...i set this object as TItem and an Array of Ulid ( Ulid[]) as TValue but the @bind-value dont valorize my result var...with Guid it work but with Ulid not
Here is my test code that im tring to make work so that i can use in al project:
//razor.cs
List<TestModel> Data2 { get; set; } = new List<TestModel>();
public Ulid[] MyItem { get; set; } = [];
public class TestModel
{
public Ulid Id { get; set; }
public string Name { get; set; } = string.Empty;
}
protected override async Task OnInitializedAsync()
{
Data2 = new List<TestModel>
{
new() { Id = Ulid.NewUlid(), Name = "Test 1" },
new TestModel { Id = Ulid.NewUlid(), Name = "Test 2" },
new TestModel { Id = Ulid.NewUlid(), Name = "Test 3" }
};
return;
}
private void ClickEvent(Microsoft.AspNetCore.Components.Web.MouseEventArgs args)
{
_ = MyItem;
}
//razor
<SfMultiSelect TValue="Ulid[]" TItem="TestModel" Placeholder="Select a game" DataSource="@Data2" @bind-Value="MyItem" Width="300px">
<MultiSelectFieldSettings Text="Name" Value="Id" />
</SfMultiSelect>
<SfButton OnClick="ClickEvent">Test</SfButton>
Hi Federico,
We have reviewed your query regarding the use of ULID with the Blazor MultiSelect component. To clarify, ULID is not a standard .NET or Microsoft-supported data type. It is typically provided by third-party libraries. Due to this, our Blazor MultiSelect component does not support ULID at the source level. In contrast, GUID is a standard .NET data type, which is why we offer built-in support for it in our components.
However, you can still use ULIDs with the MultiSelect component by converting the ULID to a string. Once converted, it can be assigned and used just like any other string value in the component.
|
<SfMultiSelect TValue="string[]" TItem="TestModel" Placeholder="Select a game" DataSource="@Data2" @bind-Value="MyItem" Width="300px"> <MultiSelectFieldSettings Text="Name" Value="Id" /> </SfMultiSelect>
@code{ List<TestModel> Data2 { get; set; } = new List<TestModel>(); public string[] MyItem { get; set; } = [];
public class TestModel { public string Id { get; set; } public string Name { get; set; } = string.Empty; }
protected override async Task OnInitializedAsync() { Data2 = new List<TestModel> { new() { Id = Ulid.NewUlid().ToString(), Name = "Test 1" }, new TestModel { Id = Ulid.NewUlid().ToString(), Name = "Test 2" }, new TestModel { Id = Ulid.NewUlid().ToString(), Name = "Test 3" } }; return; } } |
Please let us know if you need any further assistance.
Regards,
YuvanShankar A
but if i use it in a normal combobox it works...it does not work only with this component
I cant change the ulid property to string couse it is in a object request and i need it to be Ulid for validation
Hi Federico,
After further validation at the source level in our Blazor application, we have implemented the value update process differently for the ComboBox and Multi-Select components. In ComboBox, we support generic type conversion, which allows flexibility in handling various data types, including GUID. However, in the case of the Multi-Select component, the value type must be a collection, making generic conversion less feasible.
As previously mentioned, the GUID data type is a standard .NET type and does not require any third-party packages, making it fully compatible with both components. In contrast, the ULID data type requires external libraries which introduce limitations in certain scenarios. Due to this dependency and the structural differences in value handling, ULID is not currently supported in our Blazor Multi-Select component.
Query: I cant change the ulid property to string couse it is in a object request and i need it to be Ulid for validation?
We can achieve your requirement by converting the ULID values to string during the initial load and converting them back to ULID when retrieving the selected items from the Multi-Select component. This approach ensures compatibility with the component's expected value type (i.e., string[]) while still allowing you to work with ULID objects in your logic.
|
<SfMultiSelect TValue="string[]" TItem="TestModel" Placeholder="Select a game" DataSource="@Data2" @bind-Value="MyItem" Width="300px"> <MultiSelectFieldSettings Text="Name" Value="Id" /> </SfMultiSelect>
<SfButton OnClick="click">Get ULID Values</SfButton> @code { List<TestModel> Data2 { get; set; } = new List<TestModel>(); public string[] MyItem { get; set; } = [];
public class TestModel { public string Id { get; set; } public string Name { get; set; } = string.Empty; }
protected override async Task OnInitializedAsync() { Data2 = new List<TestModel> { new TestModel { Id = Ulid.NewUlid().ToString(), Name = "Test 1" }, new TestModel { Id = Ulid.NewUlid().ToString(), Name = "Test 2" }, new TestModel { Id = Ulid.NewUlid().ToString(), Name = "Test 3" } }; return; }
private void click() { List<Ulid> ulids = new(); foreach (var str in MyItem) { if (Ulid.TryParse(str, out var ulid)) { ulids.Add(ulid); } else { // Handle invalid ULID string if needed } } Ulid[] ulidArray = ulids.ToArray(); } } |
Kindly get back to us if you need any further assistance on this.
Regards,
YuvanShankar A
- 3 Replies
- 2 Participants
- Marked answer
-
FB Federico Barbero
- Jul 22, 2025 09:00 AM UTC
- Jul 30, 2025 10:02 AM UTC