ASP.NET Core MVC 2.0 / EJ 1.0 / EnrityFramework Core 2.0

Hi,
I would like to start a new project with Syncfusion ASP.NET Core MVC 2.0 and EJ 1.0.

How can I bind a entity (EntityFramework Core 2.0 - SQLServer) in a Grid Control?

Thanks,
Tommaso



1 Reply

KM Kuralarasan Muthusamy Syncfusion Team June 14, 2018 05:02 AM UTC

Hi Tommaso, 

Thanks for contacting Syncfusion support. 

According to your query you need bind data from Entity Framework model to Grid dataSource. We have prepared a sample using Entity Framework as per your requirement which can be downloaded from the below location. 


Please refer the below code example. 

 
  
[index.cshtml] 
 
<ej-grid id="FlatGrid"  datasource="ViewBag.datasource" allow-paging="true" > 
    <e-columns> 
        <e-column field="OrderID" header-text="Order ID" text-align="Right" width="75" is-primary-key="true"></e-column> 
        <e-column field="CustomerID" header-text="Customer ID" width="80"></e-column> 
        <e-column field="EmployeeID" header-text="EmployeeID" width="80"></e-column> 
        <e-column field="Verified" header-text="Verified" width="110"></e-column> 
    </e-columns> 
</ej-grid> 
 
[Homecontroller.cs] 
 
namespace WebApplication1.Controllers 
{ 
    public class HomeController : Controller 
    { 
        private NORTHWNDContext _context; 
 
        public HomeController(NORTHWNDContext context) 
        { 
            _context = context; 
        } 
 
        public IActionResult Index() 
        { 
            
            ViewBag.datasource = _context.Orders.ToList(); 
            return View(); 
        } 
 
[NORTHWNDContext.cs] 
 
namespace WebApplication1.Models 
{ 
    public partial class NORTHWNDContext : DbContext 
    { 
        public NORTHWNDContext(DbContextOptions<NORTHWNDContext> options) 
            : base(options) 
        { } 
 
        protected override void OnModelCreating(ModelBuilder modelBuilder) 
        { 
            modelBuilder.Entity<Orders>(entity => 
            { 
                entity.Property(e => e.OrderID).IsRequired(); 
            }); 
 
            modelBuilder.Entity<Employees>(entity => 
            { 
                entity.Property(e => e.EmployeeID).IsRequired(); 
            }); 
        } 
        public virtual DbSet<Orders> Orders { get; set; } 
        public virtual DbSet<Employees> Employees { get; set; } 
    } 
} 
 

Please refer the below documentation for more details of DataBinding of Grid. 


If you need any further assistance please get back to us. 

Regards,
Kuralarasan M. 
 


Loader.
Up arrow icon