Search code examples
devexpressblazordx-data-grid

DevExpress dxDataGrid for Blazor - "There was an unhandled exception on the current circuit" error


I am using dxDataGrid for Blazor to build a project,but there are some errors when I try to add a new row or edit the current row.

Error: There was an unhandled exception on the current circuit, so this circuit will be terminated. For more details turn on detailed exceptions in 'CircuitOptions.DetailedErrors'. 
[2019-09-26T11:13:47.533Z] Information: Connection disconnected.

And I got this error: enter image description here

My first thought that SignalR was disconnected.but I don't know why or how to configure?

Does anyone have any idea? Can you please tell me?

I get some new details of the error on the basis of Mikhail's suggestions . I get the first error When I first tried,and then I get the second error when I tried the second time.

Error: System.NullReferenceException: Object reference not set to an instance of an object.
Uncaught (in promise) Error: Cannot send data if the connection is not in the 'Connected' State.

It looks like something's wrong with my code.but I still don't have any ideas about the errors, so I paste my code snippet below.

<DxDataGrid Id="aa" Data="@activityDtos" @ref="@grid"
            ShowFilterRow="false"
            RowRemoving="@((dataItem) => OnRowRemoving(dataItem))"
            RowUpdating="@((updatingDataItem, newValues) => OnRowUpdating(updatingDataItem, newValues))"
            RowInserting="@((newValues) => OnRowInserting(newValues))">

    <DxDataGridCommandColumn Width="150px" Context="编辑"></DxDataGridCommandColumn>

    <DxDataGridColumn Field="@nameof(ActivityDto.ActivityCode)" Caption="Activity Code"></DxDataGridColumn>

    <DxDataGridColumn Field="@nameof(ActivityDto.ActText1)" Caption="Text1"></DxDataGridColumn>

    <DxDataGridColumn Field="@nameof(ActivityDto.ActText2)" Caption="Text2"></DxDataGridColumn>

    <DxDataGridColumn Field="@nameof(ActivityDto.ActivityStatusID)" Caption="Status">
        <DisplayTemplate>
            @{
                var feild = (context as ActivityDto).ActivityStatusID == "A" ? "Active" : "Inactive";
                <label><span>@feild</span></label>
            }
        </DisplayTemplate>
        <EditTemplate>
            <DxComboBox Data="@(new List<string>() { "Active", "Inactive" })"
                        SelectedItem="@(((bool)((CellEditContext)context).CellValue) ? "Active" : "Inactive" )"
                        SelectedItemChanged="@(newCellValue => ((CellEditContext)context).OnChanged(newCellValue == "Active"))">
            </DxComboBox>
        </EditTemplate>
    </DxDataGridColumn>

    <DxDataGridColumn Caption="Default">
        <DisplayTemplate>
            @{
                var id = Guid.NewGuid().ToString();
                var isDefault = (context as ActivityDto).IsDefault;
                <input id="@id" type="checkbox" checked="@isDefault" />
            }
        </DisplayTemplate>
    </DxDataGridColumn>

</DxDataGrid>

and there is the code of C#.

    string ActivityCode, Text1Value, Text2Value, Status,Status1;
IQueryable<ActivityDto> activityDtos;

ActivityFormDataItem editFormData = new ActivityFormDataItem()
{
    Status = "All",
    CompanyId = 37
};

protected override async Task OnInitializedAsync()
{
    activityDtos = await ActivitiesService.ActivitiesForAsync(editFormData);
    SearchDtos = await ActivitiesService.SearchDtosForAsync();
}

async void OnRowRemoving(ActivityDto dataItem)
{
    ActivitiesService.Remove(dataItem);
    await InvokeAsync(StateHasChanged);
}

async void OnRowUpdating(ActivityDto dataItem, Dictionary<string, object> newValue)
{
    ActivitiesService.Update(dataItem, newValue);
    await InvokeAsync(StateHasChanged);
}
async void OnRowInserting(Dictionary<string, object> newValue)
{
    ActivitiesService.Insert(newValue);
    await InvokeAsync(StateHasChanged);
}

protected async Task OnAfterRenderAsync()
{
    editFormData = new ActivityFormDataItem()
    {
        Status = Status1,
        ActivityCode=ActivityCode,
        CompanyId = 37,
        Text1Value=Text1Value,
        Text2Value=Text2Value
    };
    activityDtos = await ActivitiesService.ActivitiesForAsync(editFormData);
    if (!string.IsNullOrEmpty(editFormData.Status))
        editFormData.Status = editFormData.Status == "A" ? "Active" : "Inactive";
    else
        editFormData.Status = "All";
    await InvokeAsync(StateHasChanged);
}

Solution

  • I finally found out why was such a error with my code. there's a problem with type conversion when I edit the current row.

    <DxComboBox Data="@(new List<string>() { "Active", "Inactive" })"
                            SelectedItem="@(((bool)((CellEditContext)context).CellValue) ? "Active" : "Inactive" )"
                            SelectedItemChanged="@(newCellValue => ((CellEditContext)context).OnChanged(newCellValue == "Active"))">
                </DxComboBox>
    

    Actually,I wasted a lot of time because of my different direction of thinking.