C
C#3y ago
moritz

Blazor Dropdown bind to value

Is it possible to directly bind to an object instead of writing value converters?
Microsoft.AspNetCore.Components.Forms.InputSelect`1[BlazorApp1.Data.WeatherForecast] does not support the type 'BlazorApp1.Data.WeatherForecast'.
---> System.InvalidOperationException: The type 'BlazorApp1.Data.WeatherForecast' does not have an associated TypeConverter that supports conversion from a string. Apply 'TypeConverterAttribute' to the type to register a converter.
Microsoft.AspNetCore.Components.Forms.InputSelect`1[BlazorApp1.Data.WeatherForecast] does not support the type 'BlazorApp1.Data.WeatherForecast'.
---> System.InvalidOperationException: The type 'BlazorApp1.Data.WeatherForecast' does not have an associated TypeConverter that supports conversion from a string. Apply 'TypeConverterAttribute' to the type to register a converter.
@page "/counter"
@using Blazor.Extensions
@using BlazorApp1.Data
@inject IHttpContextAccessor HttpContextAccessor;
@inject WeatherForecastService Wfs;

<PageTitle>Counter</PageTitle>

<h1>Counter</h1>

<EditForm Model="@this">
<InputSelect @bind-Value="this.sf">
@foreach (var forecast in forecasts)
{
<option value=@forecast>@(forecast.TemperatureC)</option>
}
</InputSelect>
</EditForm>

@sf


@code {
private WeatherForecast[] forecasts;
public WeatherForecast sf { get; set; }

protected override async Task OnInitializedAsync()
{
forecasts = await Wfs.GetForecastAsync(DateTime.Now);
}
}
@page "/counter"
@using Blazor.Extensions
@using BlazorApp1.Data
@inject IHttpContextAccessor HttpContextAccessor;
@inject WeatherForecastService Wfs;

<PageTitle>Counter</PageTitle>

<h1>Counter</h1>

<EditForm Model="@this">
<InputSelect @bind-Value="this.sf">
@foreach (var forecast in forecasts)
{
<option value=@forecast>@(forecast.TemperatureC)</option>
}
</InputSelect>
</EditForm>

@sf


@code {
private WeatherForecast[] forecasts;
public WeatherForecast sf { get; set; }

protected override async Task OnInitializedAsync()
{
forecasts = await Wfs.GetForecastAsync(DateTime.Now);
}
}
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server