Having issues embedding RadzenDropDown in a child form. My code is as below:
<EditForm Model="@Order"
OnValidSubmit="@HandleValidSubmit"
OnInvalidSubmit="@HandleInvalidSubmit">
<DataAnnotationsValidator />
<div class="mb-3">
<label for="jobnumber" class="form-label">Job Number</label>
<InputText id="jobnumber" class="form-control" @bind-Value="Order.JobNumber" />
<ValidationMessage For="() => Order.JobNumber" />
<div class="form-group">
<div class="form=group">
<button type="button" class="btn btn-secondary"
@onclick="@(() => Order.Lines.Add(new OrderLine()))">Add Line</button>
</div>
@for (var i = 0; i < Order.Lines.Count; i++)
{
var index = i;
var orderLine = Order.Lines[i];
<h5>Line @(i+1)</h5>
<div class="form-group">
<label for="products" class="form-label">Product</label>
@*<InputSelect id="product" class="form-select selectpicker" @bind-Value="orderLine.ProductId">
@if (Products is not null)
{
@foreach (var p in Products)
{
<option value="@p.ProductId">@p.Name</option>
}
}
</InputSelect>*@
<RadzenDropDown FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
FilterOperator="StringFilterOperator.Contains"
AllowFiltering="true"
Data=@Products
TextProperty="Name"
ValueProperty="ProductID"
AllowClear="true"
@bind-Value="orderLine.ProductId"
Style="width: 100%; max-width: 400px;" />
</div>
}
</div>
</div>
@if (IsEdit)
{
<button type="submit" class="btn btn-primary" disabled="@IsBusy">Update</button>
<button type="button" class="btn btn-secondary" @onclick="@HandleCancel" disabled="@IsBusy">Cancel</button>
}
else
{
<button type="submit" class="btn btn-primary" disabled="@IsBusy">Add</button>
}
</EditForm>
So the idea is that the user can click an 'Add Line' button which will allow them to add an additional line to the current order. The drop-down allows the user to select a single product.
The Drop Down renders perfectly, and I can filter it as expected. However when I click an option in the list, I get an 'Error: System.InvalidCastException' error in the browser console.
I can't change the @bind-value to just 'ProductId' as it doesn't exist in the context as it is a value assigned to orderLine.ProductId
If I use a standard 'InputSelect' element (the one commented out above) it works perfectly. I really want to use the filterable Radzen component though.
What am I doing wrong?