【问题标题】:Can't add a row in SFGrid when Database table is empty数据库表为空时无法在 SFGrid 中添加行
【发布时间】:2021-06-07 07:45:05
【问题描述】:

如果数据库表为空,我有一个不允许我添加新行的 SfGrid(添加按钮显示为单击,但它不显示输入行)。没有错误被抛出。如果我在 SSMS(我的数据库所在的位置)中手动插入一行,则会显示该行并且我可以正常添加新行(一切正常)。 我将 Syncfusion 用于我的 Blazor-WebAssembly 项目。

这是我的剃须刀页面中的SfGrid 组件:

<SfGrid TValue="Note" Toolbar="@(new List<string>() { "Add", "Edit", "Update", "Cancel" })">
    <GridEvents OnActionBegin="OnBeginHandler" CommandClicked="@CommandClickHandler" TValue="Note"></GridEvents>
    <SfDataManager Url="/api/Notes" Adaptor="Adaptors.WebApiAdaptor"></SfDataManager>
    <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true"></GridEditSettings>
    <GridColumns>
        <GridColumn Field="@nameof(Note.NoteId)" IsPrimaryKey="true" Visible="false"></GridColumn>
        <GridColumn Field="@nameof(Note.Name)" ValidationRules="@(new ValidationRules(){Required=true})"></GridColumn>
        <GridColumn>
            <GridCommandColumns>
                <GridCommandColumn Type="CommandButtonType.Delete" ButtonOption="@(new CommandButtonOptions() { IconCss = "e-icons e-delete", CssClass = "e-flat" })"></GridCommandColumn>
            </GridCommandColumns>
        </GridColumn>
    </GridColumns>
</SfGrid> 

还有页面的@code部分:

private void OnBeginHandler(ActionEventArgs<Note> args)
{
    if (args.RequestType == Syncfusion.Blazor.Grids.Action.Save)
    {
        if (args.Action == "add")
        {
            var t = args.Data;
        }
    }
}

public void CommandClickHandler(CommandClickEventArgs<Note> args)
{
    if (args.CommandColumn.Type != CommandButtonType.Save)
        return;

    var lookup = args.RowData;

    StateHasChanged();
}

最后,NotesController

[Route("api/[controller]")]
[ApiController]
public class NotesController : ControllerBase
{
    private readonly OrganizatorContext _context;
    public NotesController(OrganizatorContext context)
    {
        _context = context;
    }

    // GET: api/<NotesController>
    [HttpGet]
    public object Get()
    {
        return new { Items = _context.Notes, Count = _context.Notes.Count() };
    }
    // GET api/<NotesController>/5

    [HttpGet("{id}")]
    public object Get(long id)
    {
        return new { Items = _context.Notes.Where(x => x.NoteId.Equals(id)).FirstOrDefault(), Count = _context.Notes.Count() };
    }

    // POST api/<NotesController>
    [HttpPost]
    public void Post([FromBody] Note note)
    {
        _context.Notes.Add(note);
        _context.SaveChanges();
    }

    // PUT api/<NotesController>/5
    [HttpPut("{id}")]
    public void Put(long id, [FromBody] Note note)
    {
        Note note1 = _context.Notes.Where(x => x.NoteId.Equals(note.NoteId)).FirstOrDefault();
        note1.Name = note.Name;
        note1.IsDone = note.IsDone;
        note1.Due = note.Due;
        _context.SaveChanges();
    }

    // DELETE api/<NotesController>/5
    [HttpDelete("{id}")]
    public void Delete(long id)
    {
        Note note1 = _context.Notes.Where(x => x.NoteId.Equals(id)).FirstOrDefault();
        _context.Notes.Remove(note1);
        _context.SaveChanges();
    }
}

【问题讨论】:

    标签: c# syncfusion blazor-webassembly syncfusion-blazor syncfusion-blazor-sfgrid


    【解决方案1】:

    我们也能够重现报告的问题。我们已经确认它是一个错误并记录了同样的缺陷报告“Can't add a row in SFGrid when Database table is empty”。感谢您花时间报告此问题并帮助我们改进产品。在 Syncfusion,我们致力于修复所有经过验证的缺陷(取决于技术可行性和产品开发生命周期),并将缺陷修复包括在 我们的版本中,预计将在年底推出 2021 年 4 月。请关注我们的 Syncfusion 页面以获取发布相关信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-26
      • 2015-09-30
      • 1970-01-01
      • 2021-08-31
      • 1970-01-01
      • 2019-08-10
      相关资源
      最近更新 更多