Using <ejs-grid> with EF Core generated (scaffolding) controller methods such as public async Task<IActionResult> Index()

Hi,

I am a beginner and just starting out (not professional, just trying to learn) please help me out;
when I run the code, the browser does not show any data, just an empty grid.

I think there is something I don't understand in the exchange of data between the controller
class and the cshtml view.

The result looks like this:




My controller class has the following code:
     // GET: Employees
     public async Task<IActionResult> Index()
     {
          ViewBag.DataSource = await _context.Employees.ToListAsync();
          return View(ViewBag.DataSource);
     }
Note: the original code only has this line "return View(await _context.Employees.ToListAsync());"


My view Index.cshtml has the following code:
     @model IEnumerable<Sample.Models.Employee>
     @{
         ViewData["Title"] = "Index";
     }
     <h2>Index</h2>
     <p>
         <a asp-action="Create">Create New</a>
     </p>
     <ejs-grid id="Grid" [email protected]>
         <e-grid-columns>
             <e-grid-column field="Code" headerText="Code" textAlign="Left" width="70"></e-grid-column>
             <e-grid-column field="DateHired" headerText="Date Hired" textAlign="Right" width="70" format="{0:MM/dd/yyyy}"></e-grid-column>
             <e-grid-column field="LastName" headerText="Last Name" width="120"></e-grid-column>
             <e-grid-column field="FirstName" headerText="First Name" width="120"></e-grid-column>
         </e-grid-columns>
     </ejs-grid>


Just in case the following information is required:
My model class has the following code:
     public class Person
     {
          public int ID { get; set; }

          [Required]
          [StringLength(50)]
          [Display(Name = "Last Name")]
          public string LastName { get; set; }

          [Required]
          [StringLength(100)]
          [Display(Name = "First Name")]
          public string FirstName { get; set; }
     }

     public class Employee : Person
     {
          [Required]
          [StringLength(20)]
          [Display(Name = "Code")]
          public string Code { get; set; }

          [Required]
          [DataType(DataType.Date)]
          [Display(Name = "Date Hired")]
          public DateTime DateHired { get; set; }
     }

Development tools and Dependencies I used:
1. Visual Studio Community 2017 v15.7.3
2. Microsoft.AspNetCore.App v2.1.0
3. Microsoft.NetCore.App v2.1.0
4. Microsoft.VisualStudio.Web.CodeGeneration.Design v2.1.0
5. Syncfusion.EJ2 v16.1.0.37 (thru NuGet Package Manager)

1 Reply

RU Ramdhas  Ueikattan Syncfusion Team June 18, 2018 01:55 PM UTC

Hi Katrina,  
 
Thanks for using Syncfusion products.  

We have tried to reproduce the reported issue at our end but its unsuccessful. We have prepared a sample for your convenience which can be download from following link,  

 
Code example:  
public async Task<IActionResult> Index()  
        {  
            ViewBag.Datasource = OrdersDetails.GetAllRecords().ToAsyncEnumerable();  
            return View();  
        }  
 
Help documentation:  

If you still face the same issue, then could you please provide following details?  

1)      Are you using webapi controller instead of default controller? If so, we need to use WebAPI adaptor for bound the data. Please refer to the following Help documentation for more information,  

2)       Share the scenario to reproduce the reported issue.  
3)      Any script error thrown in console window? If so, share the details of it.  
  
Regards,  

Ramdhas  Ueikattan 


Loader.
Up arrow icon