Grid:
@Html.AntiForgeryToken()
<ejs-grid id="Grid" allowPaging="true" load="onLoad" >
<e-grid-editsettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Batch"></e-grid-editsettings>
<e-data-manager url="/Index?handler=DataSource" batchUrl="/Index?handler=BatchUpdate" adaptor="UrlAdaptor"></e-data-manager>
<e-grid-columns>
<e-grid-column field="ShipCity" headerText="Ship City" textAlign="Right" width="120"></e-grid-column>
</e-grid-columns>
</ejs-grid>
<script>
function onLoad() {
this.dataSource.dataSource.headers = [{ 'XSRF-TOKEN': $("input:hidden[name='__RequestVerificationToken']").val() }];
}
</script>
Controller:
namespace Razorpages.Pages
{
public class IndexModel : PageModel
{
public static List<Orders> order = new List<Orders>();
public void OnGet()
{
if (order.Count == 0)
BindDataSource();
}
public class Data
{
public bool requiresCounts { get; set; }
public int skip { get; set; }
public int EmployeeID { get; set; }
public int EmployeeName { get; set; }
public int take { get; set; }
}
public JsonResult OnPostDataSource([FromBody]Data dm)
{
var data = order;
int count = data.Cast<Orders>().Count();
return dm.requiresCounts ? new JsonResult(new { result = data.Skip(dm.skip).Take(dm.take), count = count }) : new JsonResult(data);
}
}
} |