我可以使用网格更新,删除功能,但是“添加”按钮不起作用(即,我单击了“添加”按钮,但未触发“插入”事件)。社区会就我可能做错的事情提供意见吗?
Settings.cshtml:
@Html.AntiForgeryToken()
<ejs-grid id="GridNewKeywords" allowPaging="true" load="onLoad" toolbar="@( new List<object>() {" Add","Edit","Delete","Update","Cancel"})">
<e-grid-editsettings allowAdding="true" allowDeleting="true" allowEditing="true" />
<e-data-manager url="/Settings?handler=DataSource" insertUrl="/Settings?handler=Insert" updateUrl="/Settings?handler=Update" removeUrl="/Settings?handler=Delete" adaptor="UrlAdaptor" />
<e-grid-pageSettings pageCount="5" pageSize="5" />
<e-grid-columns>
<e-grid-column field="KeywordId" headerText="Id" isPrimaryKey="true" width="0" allowEditing="false" />
<e-grid-column field="UserId" headerText="UserId" isPrimaryKey="true" width="0" allowEditing="false" />
<e-grid-column field="Value" headerText="Keyword" validationRules="@(new { required=true})" />
</e-grid-columns>
</ejs-grid>
<script>
function onLoad()
{
this.dataSource.dataSource.headers = [{ 'XSRF-TOKEN': $("input:hidden[name='__RequestVerificationToken']").val() }];
}
</script>
Settings.cshtml.cs:
[ValidateAntiForgeryToken]
public class SettingsModel : PageModel
{
public async Task<JsonResult> OnPostInsert([FromBody]SyncfusionControlCrudModel<Keyword> syncfusionControlCrudModel)
{
var identityUser = await GetIdentityUserAsync();
var keyword = new Keyword()
{
UserId = identityUser.Id,
Value = syncfusionControlCrudModel.value.Value
};
ApplicationDbContext.Keywords.Add(keyword);
await ApplicationDbContext.SaveChangesAsync();
return new JsonResult(syncfusionControlCrudModel.value);
}
}
答案 0 :(得分:1)
在网格中,您已在工具栏项中的“添加” 选项(例如“添加”)之前添加了空格,这是所报告行为的原因。因此,它充当自定义工具栏项目,这就是为什么它不执行任何操作的原因(对于自定义工具栏项目,您需要在toolbarClick事件中处理相应的操作)。
<ejs-grid id="GridNewKeywords" allowPaging="true" load="onLoad" actionFailure="actionFailure"
toolbar="@( new List<object>() {"Add","Edit","Delete","Update","Cancel"})">
要解决此问题,请在“添加到”工具栏对象之前删除空格。