<EditForm Model="@model"> <SfDropDownList TValue="string" TItem="Countries" CssClass="@Validate" Width="200px" ShowClearButton="true" Placeholder="e.g. Australia" DataSource="@Country">
<DropDownListFieldSettings Text="Name" Value="Code"></DropDownListFieldSettings>
<DropDownListEvents TValue="string" ValueChange="OnChange"></DropDownListEvents>
</SfDropDownList>
</EditForm>
public void OnChange(ChangeEventArgs<string> args) {
if (args.Value == null)
{
this.Validate = "e-error";
}
else
{
this.Validate = "e-success";
}
}
|
|
|
Hello,
can you please give me a sample where the TValue is an Int ? and dropVal is type int ? It does not seems to work with type int
<EditForm Model="@model">
<DataAnnotationsValidator />
<SfDropDownList TValue="int?" TItem="Countries" Width="200px" ShowClearButton="true" @bind-Value="@model.dropVal" Placeholder="e.g. Australia" DataSource="@Country">
<DropDownListFieldSettings Text="Name" Value="Code"></DropDownListFieldSettings>
</SfDropDownList>
<ValidationMessage For="() => model.dropVal" />
<SfButton CssClass="e-small e-info" Type="submit" Content="Submit"></SfButton>
</EditForm>
@code{
public class Countries
{
public string Name { get; set; }
public int? Code { get; set; }
[Required]
public int? dropVal { get; set; } = 2;
}
List<Countries> Country = new List<Countries>
{
new Countries() { Name = "Australia", Code = 1 },
new Countries() { Name = "Bermuda", Code = 2 },
new Countries() { Name = "Canada", Code = 3 }
};
public Countries model = new Countries();
}
|
Required validation |
Success validation |
|
|