Matblazor: Matblazor Select Null value

Created on 26 Dec 2019  路  4Comments  路  Source: SamProf/MatBlazor

is there any way to binding matselect to null value
this is working
<select class="mdc-select__native-control" @bind="SecilenAtikGrubu.GrupId"> @foreach (var item in TumAtikTipleri) { <option value="@item.Id">@item.Deger1</option> } </select>
but this is not
<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>

and this is the binding class
public class GrupKodlari { [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; } }

Most helpful comment

Any update or I need to migrate to StringSelect ?

All 4 comments

Also facing the same issue. If MatSelect is bound to database and bound filed has NULL value, it is creating the error

System.NullReferenceException: Object reference not set to an instance of an object.
   at MatBlazor.MatOptionTypeKey`2.BuildRenderTree(RenderTreeBuilder __builder)
   at Microsoft.AspNetCore.Components.ComponentBase.<.ctor>b__6_0(RenderTreeBuilder builder)
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch(RenderQueueEntry renderQueueEntry)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()
Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost: Error: Unhandled exception in circuit 'sNPCplRtxjwzTlBAf1YCDGmgsWBvBOt5hX13R9wCQ7Q'.

How to handle this case when user is opening the forma and needs to fill it, so most selecions are NULL

This is how items are added to MatSelect

@foreach (var item in itemList)
{
        <MatOption TValue="int" Value="@item.id">@item.Title</MatOption>
}

Any update or I need to migrate to StringSelect ?

Hi! Thanks for using MatBlazor.
I just tried it out myself and I could bind to a null value without issues, maybe this is an issue that has been solved in recent releases.

If you still have a problem with this, can you please provide an example on www.blazorfiddle.com ?

Closing due to inactivity. Please reopen if this is still a problem for you.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Mercurial picture Mercurial  路  5Comments

esso23 picture esso23  路  5Comments

BenjaminCharlton picture BenjaminCharlton  路  3Comments

sowsan picture sowsan  路  5Comments

daviderusso1984 picture daviderusso1984  路  6Comments