I have noticed another problem when using @bind-Value for SfDropdown inside SfGrid. If the value for dropdown is nullable in the database, the Add operation is not possible (Save button of Edit Form does not work - makes no action at all and does not throw any exception). It works without selecting any value for dropdown (null) and then editing the row and changing dropdown value to desired value.
When dropdown value variable is of type not null (in the database and model), the application throws an exception when pressing the toolbar Add button, as follows:
warn: Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer[100]
Unhandled exception rendering component: Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
at Syncfusion.Blazor.DropDowns.SfDropDownList`2.getItemData()
at Syncfusion.Blazor.DropDowns.SfDropDownList`2.setValue()
at Syncfusion.Blazor.DropDowns.SfDropDownList`2.updateValues(Dictionary`2 props)
at Syncfusion.Blazor.DropDowns.SfDropDownList`2.initValue(Dictionary`2 props)
at Syncfusion.Blazor.DropDowns.SfDropDownList`2.InitialRendered()
at Syncfusion.Blazor.BaseComponent.InitComponent()
at Syncfusion.Blazor.BaseComponent.OnAfterRenderAsync(Boolean firstRender)
at Syncfusion.Blazor.DropDowns.DropDownBase`1.OnAfterRenderAsync(Boolean firstRender)
at Syncfusion.Blazor.DropDowns.SfDropDownList`2.OnHybridAfterRender(Boolean firstRender)
at Syncfusion.Blazor.DropDowns.SfDropDownList`2.OnAfterRenderAsync(Boolean firstRender)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)
fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
Unhandled exception in circuit 'vIxcqAc-D7U9cS5jcS07GhmxqgXDoyTqFaGr5BfOoGs'.
System.NullReferenceException: Object reference not set to an instance of an object.
at Syncfusion.Blazor.DropDowns.SfDropDownList`2.getItemData()
at Syncfusion.Blazor.DropDowns.SfDropDownList`2.setValue()
at Syncfusion.Blazor.DropDowns.SfDropDownList`2.updateValues(Dictionary`2 props)
at Syncfusion.Blazor.DropDowns.SfDropDownList`2.initValue(Dictionary`2 props)
at Syncfusion.Blazor.DropDowns.SfDropDownList`2.InitialRendered()
at Syncfusion.Blazor.BaseComponent.InitComponent()
at Syncfusion.Blazor.BaseComponent.OnAfterRenderAsync(Boolean firstRender)
at Syncfusion.Blazor.DropDowns.DropDownBase`1.OnAfterRenderAsync(Boolean firstRender)
at Syncfusion.Blazor.DropDowns.SfDropDownList`2.OnHybridAfterRender(Boolean firstRender)
at Syncfusion.Blazor.DropDowns.SfDropDownList`2.OnAfterRenderAsync(Boolean firstRender)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)
<SfGrid @ref="Grid" TValue="Stores" Query="@GridQuery" AllowPaging="true" AllowSorting="true" AllowReordering="false"
AllowResizing="true" AllowFiltering="false" AllowGrouping="false" ShowColumnChooser="false" Toolbar="@Tool">
<GridEvents OnActionBegin="ActionBeginHandler" TValue="Stores"></GridEvents>
<SfDataManager Url=@($"{apiURL}/stores") Adaptor="Adaptors.ODataV4Adaptor" CrossDomain="true"></SfDataManager>
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" ShowDeleteConfirmDialog="true" Mode="EditMode.Dialog">
<HeaderTemplate>
@{
var text = GetHeader((context as Stores));
<span>@text</span>
}
</HeaderTemplate>
</GridEditSettings>
<GridColumns>
<GridColumn Field=@nameof(Stores.Id) HeaderText="Id" IsPrimaryKey="true" IsIdentity="true" AllowEditing="false" Visible="false" ShowInColumnChooser="false"></GridColumn>
<GridColumn Field=@nameof(Stores.StoreId) HeaderText="Identificación" AutoFit="true"></GridColumn>
<GridColumn Field=@nameof(Stores.StoreShortName) HeaderText="Nombre Corto" AutoFit="true"></GridColumn>
<GridColumn Field=@nameof(Stores.StoreFullName) HeaderText="Nombre" AutoFit="true"></GridColumn>
<GridColumn Field=@nameof(Stores.StoreIp) HeaderText="IP" AutoFit="true"></GridColumn>
<GridColumn Field=@nameof(Stores.StoreFtpUser) HeaderText="Usuario" AutoFit="true"></GridColumn>
<GridColumn Field=@nameof(Stores.StoreFtpPassword) HeaderText="Password" AutoFit="true"></GridColumn>
<GridColumn Field=@nameof(Stores.DivsId) HeaderText="División" AutoFit="true">
<Template>
@{
var storeContext = (context as Stores);
if (storeContext.Divs != null)
{
<span>@storeContext.Divs.DivName</span>
}
}
</Template>
<EditTemplate>
<span>División</span>
<SfDropDownList ID="DivsId" @bind-Value="@((context as Stores).DivsId)" TItem="Divs" TValue="int" Placeholder="División">
<SfDataManager Url=@($"{apiURL}/divs") Adaptor="Adaptors.ODataV4Adaptor" CrossDomain="true" Offline="true"></SfDataManager>
<DropDownListFieldSettings Value="Id" Text="DivName"></DropDownListFieldSettings>
</SfDropDownList>
</EditTemplate>
</GridColumn>
</GridColumns>
</SfGrid>