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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Grid with Ef Core 3.1

Thread ID:

Created:

Updated:

Platform:

Replies:

150385 Jan 4,2020 11:58 PM UTC Jan 8,2020 05:25 AM UTC ASP.NET Core - EJ 2 4
loading
Tags: DataGrid
Gabriel
Asked On January 4, 2020 11:58 PM UTC

Hello Communitiy

I use ASP.NET Core 3.1 MVC Web App. I have following codes. I just want to show a the model class objects in the Grid. I alsow want to to a CRUD with the grid. To save the data I use EF Core.

I have no ieda why it doesn't show some data, because from the Request I get data.

Request Response: 
{"result":[{"id":"4cf8d89a-a29a-41a7-0c84-08d7913a0404","name":"asdfasdf","categories":null},{"id":"3dfbca0b-a09a-4fe1-be68-8dd67b0b78e8","name":"Income","categories":null}],"count":2}

I feel a bit stupid. I hope you can help. I think it isn't a big problem, but I need the correct hint.

Thanks a lot.

Regards
Gabriel

Model: 
public class TransactionType
{
     [Key]
     public Guid Id { get; set; }
     [Required]
     public string Name { get; set; }
     public IEnumerable<Category> Categories { get; set; }
}

DbContext:
public class BudgetControlDbContext : IdentityDbContext<Member, IdentityRole<Guid>, Guid>
{
     public BudgetControlDbContext(DbContextOptions options) : base(options) { }
      public DbSet<TransactionType> TransactionTypes { get; set; }
}

Controller:
public class TransactionTypesController : Controller
{
     private readonly BudgetControlDbContext _context;
     public TransactionTypesController(BudgetControlDbContext context)
     {
          _context = context;
     }
     public IActionResult Index() => View();
     public IActionResult UrlDatasource([FromBody]DataManagerRequest dataManager)
     {
          IEnumerable dataSource = _context.TransactionTypes.ToList();
          var operation = new DataOperations();
          if (dataManager.Search != null && dataManager.Search.Count > 0)  dataSource = operation.PerformSearching(dataSource, dataManager.Search);
          if (dataManager.Sorted != null && dataManager.Sorted.Count > 0)  dataSource = operation.PerformSorting(dataSource, dataManager.Sorted);
          if (dataManager.Where != null && dataManager.Where.Count > 0) dataSource = operation.PerformFiltering(dataSource, dataManager.Where,           dataManager.Where[0].Operator);
          var count = dataSource.Cast<TransactionType>().Count();
          if (dataManager.Skip != 0)  dataSource = operation.PerformSkip(dataSource, dataManager.Skip);
          if (dataManager.Take != 0)  dataSource = operation.PerformTake(dataSource, dataManager.Take);
          return dataManager.RequiresCounts ? Json(new { result = dataSource, count = count }) : Json(dataSource);
     }
     public ActionResult Insert(TransactionType value)
     {
          _context.TransactionTypes.Add(value);
          _context.SaveChanges();
          return Json(value);
     }
      public ActionResult Remove(Guid key)
     {
          _context.TransactionTypes.Remove(_context.TransactionTypes.Find(key));
          IEnumerable data = _context.TransactionTypes.ToList();
          var count = data.Cast<TransactionType>().Count();
          _context.SaveChanges();
          return Json(new { result = data, count });
     }
     public ActionResult Update(TransactionType value)
     {
          var transaction = value;
          var val = _context.TransactionTypes.SingleOrDefault(tt => tt.Id == transaction.Id);
          if (val != null) val.Name = transaction.Name;
          _context.SaveChanges();
          return Json(value);
     }
}

My View .cshtml:
@(Html.EJS().Grid<TransactionType>("Grid").DataSource(dataManager =>
{
    dataManager.Url("/TransactionTypes/UrlDatasource").Adaptor("UrlAdaptor").InsertUrl("/TransactionTypes/Insert").UpdateUrl("/TransactionTypes/Update").
        RemoveUrl("/TransactionTypes/Remove");
}).Width("auto").Columns(col =>
{
    col.Field("Id").HeaderText("ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Add();
    col.Field("Name").HeaderText("Name").TextAlign(TextAlign.Right).Add();
}).AllowPaging().EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true).Mode(EditMode.Normal); })
    .Toolbar(new List<string> { "Add", "Edit", "Delete", "Update", "Cancel" }).Render()) 




Balaji Sekar [Syncfusion]
Replied On January 6, 2020 01:12 PM UTC

Hi Gabriel, 
 
Thanks for contacting us. 
 
Before providing the query, It would be helpful to us to validate the issue, if you share the below details, 
 
  1. Share the Syncfusion Nuget version and CDN link version
 
  1. Share if any console error thrown
 
  1. Screenshot or video demo if the issue
 
  1. Bind the actionFailure event to Grid and share the stack trace (if any)
 
  1. If you have not any errors in console and actionFailure events , share the network tab screenshots
 
Meanwhile we are preparing the sample and update as soon as possible. 
 
Regards, 
Balaji Sekar. 


Balaji Sekar [Syncfusion]
Replied On January 7, 2020 10:09 AM UTC

Hi Gabriel, 
 
Thanks for your patience. 
 
We have prepared a sample with URL Adaptor for you convenience which can be downloaded from below link:  
 
 
In our end, it is working fine. So could you please check the provided sample if possible, try to replicate the issue in the given sample. 
 
If you still faced the issue, please share the network tab request, which will help us to validate the issue and provide the solution. 
 
For example:  
 
While Initial rendering Grid will request the server with skip and take parameters, 
 
 
 
 
In server the request: 
 
 
 
After performing server side paging data will be returned like this: