My code
-----------
C#
@page
@model NclHome.Pages.Applications.ControlPanel.HrDataManagement.TestModel
@Html.AntiForgeryToken()
@{
ViewData["Title"] = "HR Data Management";
}
{ "Edit","Cancel", "Update" })">
@section Scripts {
function onLoad() {
this.dataSource.dataSource.headers = [{ 'XSRF-TOKEN': $("input:hidden[name='__RequestVerificationToken']").val() }];
}
</script>
}.cs
--------------------------------
C#
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Syncfusion.EJ2.Base;
namespace NclHome.Pages.Applications.ControlPanel.HrDataManagement;
public class TestModel : PageModel
{
public List HrDataViewModel { get; set; } = new List();
public TestModel()
{
}
public void OnGet()
{
HrDataViewModel.Add(new HrDataViewModel
{
EmpId = 3,
FullName = "Mr. Santosh Pradhan",
DateOfSuperannuation = DateTime.Now.AddDays(-2),
IsWorking = true
});
HrDataViewModel.Add(new HrDataViewModel
{
EmpId = 4,
FullName = "Mr. Sekhar Pradhan",
DateOfSuperannuation = DateTime.Now.AddDays(-3),
IsWorking = false
});
HrDataViewModel.Add(new HrDataViewModel
{
EmpId = 5,
FullName = "Mr. Deepak Pradhan",
DateOfSuperannuation = DateTime.Now.AddDays(1),
IsWorking = false
});
}
public async Task OnPostUpdateAsync([FromBody] CRUDModel crudModel)
{
//update logic Here
return new JsonResult(crudModel.Value);
}
}
public class HrDataViewModel
{
public int EmpId { get; set; }
public string FullName { get; set; }
public DateTime? DateOfSuperannuation { get; set; }
public bool? IsWorking { get; set; }
}
Jayraj ChhayaRank #304 · 8.2K reputationPosted Dec 15, 2023, 1:01 AM EST
The code has a bug that prevents the inline editing functionality from working correctly for the
CauseDateOfSuperannuationandIsWorkingcolumns. When attempting to edit these columns inline, the changes are not saved.The cause of the bug is that the
SolutionDateOfSuperannuationandIsWorkingproperties in theHrDataViewModelclass are not marked as editable. This prevents the grid from recognizing these columns as editable and saving the changes.To fix the bug and enable inline editing for the
DateOfSuperannuationandIsWorkingcolumns, you need to update theHrDataViewModelclass and the grid configuration in the Razor page.HrDataViewModelclass, add the[Editable(true)]attribute to theDateOfSuperannuationandIsWorkingproperties. This attribute marks the properties as editable.public class HrDataViewModel { public int EmpId { get; set; } public string FullName { get; set; } [Editable(true)] public DateTime? DateOfSuperannuation { get; set; } [Editable(true)] public bool? IsWorking { get; set; } }e-grid-columnssection to include theeditproperty for theDateOfSuperannuationandIsWorkingcolumns. Set theeditproperty totrueto enable inline editing for these columns.With these changes, the
DateOfSuperannuationandIsWorkingcolumns will be editable, and any changes made inline will be saved.