I can't seem to get the grid to work with my database. everything works fine until I take out the prebuilt data, and try to get it to pull data from my models.
Just shows No results found.
I'm under the impression that I don't understand the Datamanager documentation. I've tried what feels like every possible scenario in the docs. any help would be appreciated.
When I use this method I get the following error:
KeyNotFoundException: The given key 'CurrentClass' was not present in the dictionary.
System.Collections.Generic.Dictionary
.get_Item(TKey key) Syncfusion.EJ2.EJTagHelper.GetChildContent(TagHelperContext context, TagHelperOutput output)
Syncfusion.EJ2.EJTagHelper.Process(TagHelperContext context, TagHelperOutput output)
Microsoft.AspNetCore.Razor.TagHelpers.TagHelper.ProcessAsync(TagHelperContext context, TagHelperOutput output)
Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner.RunAsync(TagHelperExecutionContext executionContext)
AspNetCore.Views_LocationModels_Index.ExecuteAsync()
Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)
Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, bool invokeViewStarts)
Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, string contentType, Nullable
statusCode) Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, string contentType, Nullable
statusCode) Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ActionContext actionContext, IView view, ViewDataDictionary viewData, ITempDataDictionary tempData, string contentType, Nullable
statusCode) Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result)
Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.
g__Awaited|29_0 (ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext
(ref State next, ref Scope scope, ref object state, ref bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.
g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.
g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) Microsoft.AspNetCore.Routing.EndpointMiddleware.
g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger) Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
If I remove "
<e-data-manager url="LocationModels/UrlDatasource" insertUrl="/LocationModels/Insert" updateUrl="/LocationModels/Update" removeUrl="/LocationModels/Remove" adaptor="UrlAdaptor"></e-data-manager>
" from the View file index.cshtml
It will load, but without data, obviously.
I moved the <e-data-manager> tags within the <ejs-grid> tags and got rid of the error, however, the page now loads, but without a table/grid/data anthing.
|
<ejs-grid id="Grid" height="272" allowPaging="true" allowSorting="true" toolbar="@(new List<string>() { "Add", "Edit", "Delete","Update","Cancel" })">
<e-data-manager url="/DataGrid/UrlDataSource" adaptor="UrlAdaptor" insertUrl="/DataGrid/Insert" updateUrl="/DataGrid/Update" removeUrl="/DataGrid/Delete"></e-data-manager>
<e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Normal"></e-grid-editSettings>
<e-grid-columns>
<e-grid-column field="OrderID" headerText="OrderID" isIdentity="true" defaultValue=0 isPrimaryKey="true"></e-grid-column>
<e-grid-column field="CustomerID" headerText="CustomerID"></e-grid-column>
</e-grid-columns>
</ejs-grid> |
|
public class DataGridController : Controller
{
private OrderDbContext _context;
public DataGridController(OrderDbContext Context)
{
this._context=Context;
}
public ActionResult Index()
{
return View();
}
public ActionResult UrlDatasource([FromBody]DataManagerRequest dm)
{
// here we are retrieving the data from DB to display the records in grid
IEnumerable DataSource = _context.Orders.ToList();
DataOperations operation = new DataOperations();
if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting
{
DataSource = operation.PerformSorting(DataSource, dm.Sorted);
}
int count = DataSource.Cast<Orders>().Count();
if (dm.Skip != 0)//Paging
{
DataSource = operation.PerformSkip(DataSource, dm.Skip);
}
if (dm.Take != 0)
{
DataSource = operation.PerformTake(DataSource, dm.Take);
}
return Json(new { result = DataSource, count = count });
}
public ActionResult Insert([FromBody]CRUDModel<Orders> value)
{
//here you can add data to your db
_context.Orders.Add(value.Value);
_context.SaveChanges();
return Json(value);
}
public ActionResult Update([FromBody]CRUDModel<Orders> value)
{
//here you can update data in your db
var ord = value;
Orders val = _context.Orders.Where(or => or.OrderID == ord.Value.OrderID).FirstOrDefault();
val.OrderID=ord.Value.OrderID;
val.CustomerID=ord.Value.CustomerID;
_context.SaveChanges();
return Json(value);
}
public ActionResult Delete([FromBody]CRUDModel<Orders> value)
{
//here you can perform delete action your db
Orders order = _context.Orders.Where(c => c.OrderID == (int)value.Key).FirstOrDefault();
_context.Orders.Remove(order);
_context.SaveChanges();
return Json(order);
}
} |
|
{
public class OrderDbContext: DbContext
{
public virtual DbSet<Orders> Orders { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
// here we have accessed the NorthWind DB
string directory = Directory.GetCurrentDirectory();
string dir = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=" + directory + \\AppData\\NORTHWND.MDF;Integrated Security=True;
optionsBuilder.UseSqlServer(dir);
}
}
}
} |
Thank you I believe this has gotten it working.