【发布时间】:2020-02-17 11:49:07
【问题描述】:
我正在尝试将模型中的 CountryId 绑定到 Blazor 中 SelectList 的选定项的值。所有 Country 项目都在一个类似 {CountryId, CountryName} 对象的列表中。我这样做的代码是这样的:
<InputSelect @bind-Value="model.ByCountryId" class="form-control">
@if (model?.Countries != null)
{
@foreach (var cnt in model.Countries)
{
<option value="@cnt.Id">@cnt.Name</option>
}
}
</InputSelect>
还有代码块:
@code {
BrandModel model = new BrandModel();
protected override async Task OnInitializedAsync()
{
model = new BrandModel
{
Id = 19,
ByCountryId = 1,
Countries = new List<ent.Country>
{
new ent.Country { Id = 1, Name = "Azerbaijan" },
new ent.Country { Id = 2, Name = "Turkey" }
},
IsActive = true,
Name = "Brand"
};
}
但是这个执行在浏览器中给了我这个错误:
blazor.webassembly.js:1 WASM: System.MissingMethodException: 找不到类型“System.ComponentModel.ByteConverter”的构造函数。
在 Blazor 中绑定 <select> 和 model.data 的便捷方式是什么?
【问题讨论】:
标签: c# asp.net asp.net-core blazor