Hi All,
I have a problem. I've a not working grid. I do a compilated query for get the data but the data never gets loaded in the grid.
What is the error? Thanks in advance for any help.
Content of controller
using DataLayerIAccess.Repository;
using DataLayerIAccess.Repository.Queries;
using Kendo.Mvc.Extensions;
using Kendo.Mvc.UI;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using System.Threading.Tasks;
using WebViewerIAccess.Models;
namespace WebViewerIAccess.Controllers
{
public class GridController : Controller
{
private readonly IAccessDbContext _context;
public GridController(IAccessDbContext context)
=> _context = context;
public async Task<IActionResult> ElencoPresenze_Read([DataSourceRequest] DataSourceRequest request)
{
var elencoPresenze = (await _context.GetElencoPresenze(0, 10)).ToList();
var presenzeViewModel = Utilities.MapFromAType<PresenzeModel>(elencoPresenze);
var dsResult = presenzeViewModel.ToDataSourceResult(request);
return Json(dsResult);
}
Content of .cshtml
@{
ViewData["Title"] = "Presenze";
}
<div class="text-center">
@(Html.Kendo().Grid<WebViewerIAccess.Models.PresenzeModel>()
.Name("grid")
.Columns(c => {
c.Bound(p => p.ID);
c.Bound(p => p.Nome);
c.Bound(p => p.Cognome);
c.Bound(p => p.Giorno);
c.Bound(p => p.Reparto);
}) .Pageable(p => p
.PageSizes(new[] { 10, 20, 50 })
.Refresh(true)
.Responsive(true))
.Sortable()
.Filterable()
.Scrollable()
.Groupable()
.DataSource(ds => ds
.Ajax()
.Batch(true)
.PageSize(20)
.AutoSync(true)
.ServerOperation(false)
.Events(e => e.Error("error_handler"))
.Model(m => {
m.Field(p => p.ID);
m.Field(p => p.Nome);
m.Field(p => p.Cognome);
})
.AutoSync(true)
.Read(r => r.Action("ElencoPresenze_Read", "Grid"))
</div>
<script type="text/javascript">
function error_handler(e) {
if (e.errors) {
var message = "Errors:\n";
$.each(e.errors, function (key, value) {
if ('errors' in value) {
$.each(value.errors, function () {
message += this + "\n";
});
}
});
alert(message);
}
}
</script>
Content of Model
using System;
namespace WebViewerIAccess.Models
{
public class PresenzeModel
{
public int ID { get; set; }
public string Nome { get; set; }
public string Cognome { get; set; }
public DateTime Giorno { get; set; }
public string Reparto { get; set; }
}
}
thank you