Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
142877 | Feb 24,2019 07:25 PM UTC | Mar 4,2019 12:04 PM UTC | ASP.NET Core - EJ 2 | 3 |
![]() |
Tags: DataGrid |
[View page]
<ejs-grid id="Grid" ...>
<e-data-manager json="@Model.DataSource.ToArray()" adaptor="RemoteSaveAdaptor"></e-data-manager>
...
</ejs-grid>
[Controller code]
namespace Razorpages.Pages
{
public class IndexModel : PageModel
{
public List<OrdersDetails> DataSource = OrdersDetails.GetAllRecords();
public void OnGet()
{
}
...
}
}
|
This works, thanks!
Here is the complete Razor Pages Code, in case someone is interested:
CSHTML Batch Editing
@page
@model IndexModel
@{
ViewData["Title"] = "EJ2 Grid Test Batch Edit Mode";
}
<ejs-grid id="Grid" toolbar="@(new List<string>() { "Add","Delete","Update", "Cancel" })">
<e-data-manager json="@Model.Books.ToArray()" adaptor="RemoteSaveAdaptor" insertUrl="Index?handler=ActionHere" updateUrl="Index?handler=ActionHere" removeUrl="Index?handler=ActionHere" batchUrl="Index?handler=ActionHere"></e-data-manager>
<e-grid-editSettings allowDeleting="true" allowEditing="true" allowAdding="true" mode="Batch"></e-grid-editSettings>
<e-grid-columns>
<e-grid-column field="Id" headerText="Id" textAlign="Right" width="120"></e-grid-column>
<e-grid-column field="BookName" headerText="Book Name" width="150"></e-grid-column>
<e-grid-column field="EAN" headerText="EAN" width="130" textAlign="Right"></e-grid-column>
</e-grid-columns>
</ejs-grid>
CSHTML.cs Code Behind File
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Syncfusion.EJ2.Base;
namespace TheDefinitveGridEJ2.Pages
{
[IgnoreAntiforgeryToken(Order = 1001)]
public class IndexModel : PageModel
{
public List<Book> Books = new List<Book>();
public void OnGet()
{
bool isEmpty = !Books.Any();
if(isEmpty)
{
GetDataSource();
}
}
public void GetDataSource()
{
Books.Add(new Book() { Id = 44, BookName = "Cool", EAN = "4444444444444" });
Books.Add(new Book() { Id = 55, BookName = "Cool1", EAN = "55555555555" });
Books.Add(new Book() { Id = 66, BookName = "Cool2", EAN = "66666666666" });
}
public IActionResult OnPostActionHere([FromBody]CRUDModel<Book> myObject)
{
// SET BREAKPOINT HERE. CRUD Operations can be made to a MS SQL Database at this place. Take a look at myObject during break, various information can be gathered from myObject.
return Page();
}
public class Book
{
public int Id { get; set; }
public string BookName { get; set; }
public string EAN { get; set; }
}
}
}
This post will be permanently deleted. Are you sure you want to continue?
Sorry, An error occured while processing your request. Please try again later.
This page will automatically be redirected to the sign-in page in 10 seconds.