my code should be like this, but it's getting null reference exception
<MatSelect Label="Atık Tipi" @bind-Value="@SecilenAtikGrubu.GrupId" Style="width:100%">
@foreach (var item in TumAtikTipleri)
{
<MatOption Value="@item.Id">@item.Deger1</MatOption>
}
</MatSelect>
but when i use like this, it is working
<select class="mdc-select__native-control" @bind="SecilenAtikGrubu.GrupId">
@foreach (var item in TumAtikTipleri)
{
<option value="@item.Id">@item.Deger1</option>
}
</select>
Binding value class is like below (SecilenAtikGrubu and TumAtikTipleri)
public class GrupKodlari : KayitBilgisi
{
[Key]
public int Id { get; set; }
public string Tur { get; set; }
public string Isim { get; set; }
public string Deger1 { get; set; }
public string Deger2 { get; set; }
public string Deger3 { get; set; }
public int? GrupId { get; set; }
public virtual GrupKodlari Grup { get; set; }
}
The bad news are that, I have checked it and, MatSelect is unable to be binded to a nullable type.
Now the good news, first one, you can use an auxiliary property as a workaround, Try it at blazorfiddle.
Second good new: MatBlazor is an opensource project. If you need to work with nullable types you can improve MatSelect control and send a PR. The project owner is open to contributions (for example I wrote NumericUpDown) If you can't improve component, you can pay someone to write it for you or you can post a request for the new feature on project issues. It looks like good idea, would be wonderful to bind nullable objects.