Hello,
I have an dropdownlist on my page with a editform, when select value and after I save the record.
The binding value of dropdownlist is always null.
I try to implement the event but not working.
I use a Blazor Web Assembly asp.netcore hosted.
It's possible to have an example or tutorial where in editform save data in database with dropdownlist ?
This my code razor:
<EditForm Model="@vis" OnValidSubmit="@OnValidSubmit">
....................
<div class="form-group p-2">
<div>
<SfDropDownList TValue="int?" TItem="Paziente" Placeholder="Seleziona Paziente" Query="@query" @bind-Value="@vis.Id_Paziente">
<SfDataManager Url="/api/Paziente" Adaptor="Adaptors.WebApiAdaptor" CrossDomain="true"></SfDataManager>
<DropDownListEvents ValueChange="ComboBoxItemSelected" TItem="Paziente" TValue="int?"></DropDownListEvents>
<DropDownListFieldSettings Text="Nome" Value="id"></DropDownListFieldSettings>
</SfDropDownList>
</div>
</div>
and this my code:
@code {
[Parameter] public Visita vis { get; set; }
[Parameter] public string ButtonText { get; set; } = "Salva";
[Parameter] public EventCallback OnValidSubmit { get; set; }
public Query query = new Query().Select(new List<string> { "id", "nome" }).Take(6).RequiresCount();
async Task ComboBoxItemSelected(Syncfusion.Blazor.DropDowns.ChangeEventArgs<int?, Paziente> args)
{
//if (args != null)
//{
// //Do Work...
//}
}
}
|
<SfDropDownList TValue="string" TItem="EmployeeData" Placeholder="Select an Employee" @bind-Value="@model.FirstName" DataSource="@Data">
<DropDownListFieldSettings Value="FirstName" Text="FirstName" />
<DropDownListEvents ValueChange="ComboBoxItemSelected" TValue="string" TItem="EmployeeData"></DropDownListEvents>
</SfDropDownList>
@code {
public class EmployeeData
{
[Required(ErrorMessage = "The Employee field is required.")]
public string FirstName { get; set; }
public string Designation { get; set; }
public string Eimg { get; set; }
}
private List<EmployeeData> Data = new List<EmployeeData>
{
new EmployeeData() { FirstName = "Andrew Fuller", Designation = "Team Lead", Eimg= "7" },
new EmployeeData() { FirstName = "Anne Dodsworth", Designation = "Developer", Eimg= "1" },
new EmployeeData() { FirstName = "Janet Leverling", Designation = "HR", Eimg= "3" },
new EmployeeData() { FirstName = "Laura Callahan", Designation = "Product Manager", Eimg= "2" },
new EmployeeData() { FirstName = "Margaret Peacock", Designation = "Developer", Eimg= "6" },
new EmployeeData() { FirstName = "Michael Suyama", Designation = "Team Lead", Eimg= "9" },
new EmployeeData() { FirstName = "Nancy Davolio", Designation = "Product Manager", Eimg= "4" },
new EmployeeData() { FirstName = "Robert King", Designation = "Developer", Eimg= "8" },
new EmployeeData() { FirstName = "Steven Buchanan", Designation = "CEO", Eimg= "10" }
};
async Task ComboBoxItemSelected(Syncfusion.Blazor.DropDowns.ChangeEventArgs<string, EmployeeData> args)
{
Console.WriteLine("changed component value: " +args.Value);
//if (args != null)
//{
// //Do Work...
//}
}
} |
|
|
|
<EditForm Model="@model" OnValidSubmit="@OnValidSubmit">
<DataAnnotationsValidator />
<div>
<SfDropDownList TValue="string" TItem="EmployeeData" Placeholder="Select an Employee" @bind-Value="@model.FirstName" DataSource="@Data">
<DropDownListFieldSettings Value="FirstName" Text="FirstName" />
<DropDownListEvents ValueChange="ComboBoxItemSelected" TValue="string" TItem="EmployeeData"></DropDownListEvents>
</SfDropDownList>
<ValidationMessage For="()=>model.FirstName" />
</div>
<div class="sfButton">
<SfButton type="submit" IsPrimary="true">Submit</SfButton>
</div>
</EditForm>
@code {
async void OnValidSubmit()
{
var SelectedValue = model.FirstName;
Console.WriteLine("form submit value: "+model.FirstName);
StateHasChanged();
}
private EmployeeData model = new EmployeeData();
public class EmployeeData
{
[Required(ErrorMessage = "The Employee field is required.")]
public string FirstName { get; set; }
public string Designation { get; set; }
public string Eimg { get; set; }
}
private List<EmployeeData> Data = new List<EmployeeData>
{
new EmployeeData() { FirstName = "Andrew Fuller", Designation = "Team Lead", Eimg= "7" },
new EmployeeData() { FirstName = "Anne Dodsworth", Designation = "Developer", Eimg= "1" },
new EmployeeData() { FirstName = "Janet Leverling", Designation = "HR", Eimg= "3" },
new EmployeeData() { FirstName = "Laura Callahan", Designation = "Product Manager", Eimg= "2" },
new EmployeeData() { FirstName = "Margaret Peacock", Designation = "Developer", Eimg= "6" },
new EmployeeData() { FirstName = "Michael Suyama", Designation = "Team Lead", Eimg= "9" },
new EmployeeData() { FirstName = "Nancy Davolio", Designation = "Product Manager", Eimg= "4" },
new EmployeeData() { FirstName = "Robert King", Designation = "Developer", Eimg= "8" },
new EmployeeData() { FirstName = "Steven Buchanan", Designation = "CEO", Eimg= "10" }
};
async Task ComboBoxItemSelected(Syncfusion.Blazor.DropDowns.ChangeEventArgs<string, EmployeeData> args)
{
Console.WriteLine("changed component value: " +args.Value);
//if (args != null)
//{
// //Do Work...
//}
}
} |
Thank,
now I try.
In my code I have :
<SfDataManager Url="/api/Paziente" Adaptor="Adaptors.WebApiAdaptor" CrossDomain="true"></SfDataManager>
Could this be a problem?
|
<SfDropDownList TValue="string"
TItem="Countries"
Placeholder="Select country"
DataSource="@Country" @bind-Value="SetBindValue" >
<DropDownListFieldSettings Value="Code" Text="Name"></DropDownListFieldSettings>
@*<DropDownListEvents TValue="string" TItem="Countries" ValueChange="onValueChange"></DropDownListEvents>*@
</SfDropDownList>
[index.razor]
<CountryComponent SetBindValue="@CountryCode"></CountryComponent>
|
Thank for all.