@using Syncfusion.Blazor.DropDowns
@using System.ComponentModel.DataAnnotations
<EditForm EditContext="@editContext">
<DataAnnotationsValidator />
<div class="form-group">
<SfComboBox TValue="string" TItem="Countries" AllowCustom="false" Placeholder="e.g. Australia" @bind-Value="@model.ComboVal" DataSource="@Country">
<ComboBoxFieldSettings Value="Name"></ComboBoxFieldSettings>
</SfComboBox>
<ValidationMessage For="() => model.ComboVal" />
</div>
<button>Submit</button>
</EditForm>
@code {
public class Countries
{
public string Name { get; set; }
public int? Code { get; set; }
}
List<Countries> Country = new List<Countries>
{
new Countries() { Name = "TestCountry1", Code = 11 },
new Countries() { Name = "TestCountry2", Code = 12 },
new Countries() { Name ="TestCountry3", Code = 13 },
new Countries() { Name = "TestCountry4", Code = 14 },
};
private Test model;
private EditContext editContext;
protected override void OnInitialized()
{
model = new Test();
editContext = new EditContext(model);
}
public class Test
{
[Required]
public string ComboVal { get; set; }
}
}
|