The update and delete operation the grid is OK.But the Add operation is not working, when I try to add a record, after click "save" the record doesn't go to the db, even no event was triggerred at ActionBeginningHandler and ActionCompleteHandler.
Source code of this page is below:
@page "/user" @using Newtonsoft.Json @using BaseBLL.Helper.ResponseList @using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage @inject ProtectedLocalStorage BrowserStorage @inject HttpClient httpClient @inject NavigationManager navigationManager @inject ConfigHelper configHelper @inject UserDataService userDataService @{ var Tool = (new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel", "ExcelExport", "Search" }); } @{ var pageSize = (new List<int>() { 10, 20, 50, 100 }); } <SfGrid DataSource="@Users" ID="DefaultGrid" @ref="DefaultGrid" TValue="TblUser" Toolbar="Tool" AllowSorting="true" AllowFiltering="true" AllowPaging="true" AllowExcelExport="true"> <GridEvents OnActionBegin="ActionBeginHandler" OnActionComplete="@ActionCompletedHandler" OnToolbarClick="ToolbarClickHandler" TValue="TblUser" OnActionFailure="@ActionFailure" ></GridEvents> <GridFilterSettings Type="Syncfusion.Blazor.Grids.FilterType.Menu"></GridFilterSettings> <GridPageSettings PageSize="10" PageCount="10" PageSizes="@pageSize"></GridPageSettings> @*<SfDataManager @ref="dm" Url="odata/dysonusers" Headers="@HeaderData" Adaptor="Adaptors.ODataV4Adaptor"></SfDataManager>*@ <GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" Mode="EditMode.Dialog"> </GridEditSettings> <GridColumns> <GridColumn Field=@nameof(TblUser.Avatar) HeaderText="Avatar" Visible="true" TextAlign="TextAlign.Center"></GridColumn> <GridColumn Field=@nameof(TblUser.UserGUID) HeaderText="Id" IsPrimaryKey="true" IsIdentity="true" Visible="false" TextAlign="TextAlign.Center"></GridColumn> <GridColumn Field=@nameof(TblUser.UserName) HeaderText="UserName" Visible="true" TextAlign="TextAlign.Center"></GridColumn> <GridColumn Field=@nameof(TblUser.Email) HeaderText="Email" Visible="true" TextAlign="TextAlign.Center"></GridColumn> <GridColumn Field=@nameof(TblUser.UserType) HeaderText="UserType" Visible="true" TextAlign="TextAlign.Center"></GridColumn> <GridColumn Field=@nameof(TblUser.Department) HeaderText="IDepartmentd" Visible="true" TextAlign="TextAlign.Center"></GridColumn> <GridColumn Field=@nameof(TblUser.Description) HeaderText="Description" Visible="true" TextAlign="TextAlign.Center"></GridColumn> </GridColumns> </SfGrid> @code { private bool IsVisible { get; set; } = false; public string ErrorDetails = ""; public IEnumerable<TblUser> Users { get; set; } private SfGrid<TblUser> DefaultGrid; public SfDataManager dm { get; set; } [CascadingParameter] private IDictionary<string, string> HeaderData { get; set; } [CascadingParameter] private UserInfo CurrentUserInfo { get; set; } [CascadingParameter] private HttpClient DysonHttpClient { get; set; } private Boolean Check = false; protected override void OnInitialized() { Users = userDataService.Get(); } public void ActionBeginHandler(ActionEventArgs<TblUser> args) { if (args.RequestType.ToString() == "Add") { Check = true; } else { Check = false; } if (args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Save)) { if (args.Action == "Add") { userDataService.Insert(args.Data); } else { userDataService.Update(args.Data.UserGUID, args.Data); } } if (args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Delete)) { userDataService.Delete(args.Data.UserGUID); } } private void OpenDialog() { this.IsVisible = true; } private void CloseDialog() { this.IsVisible = false; } public async Task ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args) { if (args.Item.Id == "DefaultGrid_excelexport") //Id is combination of Grid's ID and itemname { await this.DefaultGrid.ExcelExport(); } } public void ActionCompletedHandler(ActionEventArgs<TblUser> args) { if (args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Save)) { Users = userDataService.Get(); //to fetch the updated data from db to Grid } } protected override void OnAfterRender(bool firstRender) { base.OnAfterRender(firstRender); //User这块暂时先用回patch协议,有问题再切换去put协议 //if (dm != null) //{ // RemoteOptions Rm = (dm.DataAdaptor as ODataV4Adaptor).Options; // Rm.UpdateType = HttpMethod.Put; // (dm.DataAdaptor as ODataV4Adaptor).Options = Rm; //} } public void MultiSelectActionFailure(Exception ex) { this.ErrorDetails = ex.Message; this.IsVisible = true; OpenDialog(); Console.WriteLine(ex); } protected void OnTagging(TaggingEventArgs<TblRole> args) { System.Diagnostics.Debug.WriteLine($"OnTagging() -- selectedTags"); } public void ActionFailure(Syncfusion.Blazor.Grids.FailureEventArgs args) { if (args.Error.Message != null) { var msg = args.Error.Message; if ((!string.IsNullOrEmpty(msg) && msg.IndexOf("401") != -1) || (!string.IsNullOrEmpty(msg) && msg.IndexOf("000009") != -1) || ("Value cannot be null. (Parameter 'source')".Equals(msg))) { try { //var InternalMessage = args.Error.InnerException.Message; //TechManResponse res = JsonConvert.DeserializeObject<TechManResponse>(InternalMessage); //if (res.ResultCode == BaseModels.Entity.Enums.CommonEnum.ResultCode.NotLogin) //{ navigationManager.NavigateTo("/login", true); //} } catch { } } //所有其他情况,只报错 this.ErrorDetails = msg; this.IsVisible = true; OpenDialog(); } StateHasChanged(); } } |