We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Binding

Hello.

I'm using VS 2017 MVC .net Core Entity Framework Core.  The data is not binding.  I suspect maybe I need to reference something else in the DataSource.

I've Design First reverse engineered my models and add controller to create the scaffolding (CRUD) pages.

Now I have a table that is looping and building a grid, and I'm replacing it with Syncfusion GRID.

This is my Controler:
        public TblContractzsController(ContractsContext context)
        {
            _context = context;
        }

        // GET: TblContractzs
        public async Task<IActionResult> Index()
        {
            return View(await _context.TblContractz.ToListAsync());
            //ViewBag.datasource = _context.TblContractz.ToList();
            //return View();
        }

This is my View:
    <ejs-grid id="Grid" Datasource="ViewBag.datasource" allowPaging="true">

        <e-grid-columns>
            <e-grid-column field="ContractName" headerText="Contract Name" textAlign="Right" width="120"></e-grid-column>

        </e-grid-columns>

    </ejs-grid>



1 Reply

TS Thavasianand Sankaranarayanan Syncfusion Team May 30, 2019 10:58 AM UTC

Hi Erin,  

Thanks for contacting Syncfusion support  

Query: “The data is not binding.  I suspect maybe I need to reference something else in the DataSource. 
 
From your query, we understand that you are facing issue while binding dataSource to Grid using entity framework. In your code example you have returned the dataSource instead of binding it to ViewBag. This may the  cause of the issue. Kindly assign the dataSource to Viewbag and define the dataSource to Grid. Refer the below modified code example 

<ejs-grid id="Grid" Datasource="ViewBag.datasource" allowPaging="true"> 
 
    <e-grid-columns> 
        <e-grid-column field="OrderID" headerText="Contract Name" textAlign="Right" width="120"></e-grid-column> 
 
    </e-grid-columns> 
 
</ejs-grid> 

…………………….. 

public async Task<IActionResult> Index() 
        { 
           // await _context.Orders.ToList(); 
           // return View(); 
            ViewBag.datasource = _context.Orders.Take(100).ToList(); 
            return View(); 
        } 

Refer the below screenshot for the output 

 

For your convenience we have prepared a sample which can be downloaded from below link  


Please get back to us if you have further queries.   

Regards, 
Thavasianand S.  


Loader.
Live Chat Icon For mobile
Up arrow icon