Asp.net mvc 剑道UI网格不显示数据库中的数据
我有一个剑道UI网格,它应该显示从实体框架加载的数据,链接到SQL数据库。一切正常,但数据突然停止显示在网格中 因此,我: Index.cshtmlAsp.net mvc 剑道UI网格不显示数据库中的数据,asp.net-mvc,kendo-ui,grid,Asp.net Mvc,Kendo Ui,Grid,我有一个剑道UI网格,它应该显示从实体框架加载的数据,链接到SQL数据库。一切正常,但数据突然停止显示在网格中 因此,我: Index.cshtml @( Html.Kendo().Grid<Localidade>() .Name("LocalidadesGrid") .Columns( column => { column.Bound(e => e.nome).
@(
Html.Kendo().Grid<Localidade>()
.Name("LocalidadesGrid")
.Columns(
column =>
{
column.Bound(e => e.nome).Title("Nome").Groupable(false).Width(70);
column.Bound(e => e.cod_postal).Title("Código Postal").Groupable(false).Width(30);
column.Command(command => { command.Edit().Text("Editar").UpdateText("Guardar").CancelText("Cancelar");
command.Destroy().Text("Remover"); }).Width(172);
}
)
.ToolBar(toolbar => toolbar.Create().Text("Criar Nova Localidade"))
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Filterable()
.Selectable()
.Sortable()
.Pageable(page =>
page.Refresh(true)
.PageSizes(true)
.PreviousNext(true)
.Messages(m => m.ItemsPerPage("Localidades por página")
.Display("{0}-{1} de {2}")
.First("Primeira página")
.Last("Última página")
.Previous("Página anterior")
.Next("Página seguinte"))
)
.Reorderable(reorder => reorder.Columns(true))
.DataSource(
datasource => datasource
.Ajax()
.PageSize(10)
.Model(model => { model.Id(p => p.id); model.Field(p => p.id).Editable(false); })
.Create(update => update.Action("EditingInLine_Create", "Localidades"))
.Read(read => read.Action("GetLocalidades", "Localidades"))
.Update(update => update.Action("EditingInLine_Update", "Localidades"))
.Destroy(update => update.Action("EditingInLine_Destroy", "Localidades"))
)
)
当从LocalidadesController调用GetLocalidades时,它给了我一个内部服务器错误。我还尝试返回一个JsonResult而不是ActionResult,但是错误没有得到解决
编辑:
我在输出中得到这个:
The thread 'Win32 Thread' (0x1024) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x1020) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0xaf8) has exited with code 0 (0x0).
A first chance exception of type 'System.InvalidOperationException' occurred in System.Web.Extensions.dll
A first chance exception of type 'System.InvalidOperationException' occurred in System.Web.Mvc.dll
A first chance exception of type 'System.InvalidOperationException' occurred in System.Web.Mvc.dll
我终于找到了解决办法。也许这不是最好的,但据我所知,它工作得很好 我没有将模型传递给视图,而是在ViewBag的帮助下发送一个IEnumerable,其中包含我想要绑定到网格的所有模型 在控制器中,我将数据绑定到ViewBag:
public ActionResult Index()
{
db = new quest_geralEntities();
ViewBag.localidades = db.Localidade.Select(localidade => new LocalidadeViewModel
{
id = localidade.id,
nome = localidade.nome,
cod_postal = localidade.cod_postal
});
return View();
}
视图:
@(
Html.Kendo().Grid((IEnumerable<LocalidadeViewModel>) ViewBag.localidades)
.Name("grid")
)
@(
Html.Kendo().Grid((IEnumerable)ViewBag.localidades)
.名称(“网格”)
)
另外,我已经创建了一个ViewModel来解决我遇到的循环引用异常
这样数据显示正确,我仍然能够使用所有CRUD操作
我希望它能帮助别人 查看内部服务器错误的详细信息。如果可能的话,发布堆栈跟踪。我已经用VS给我的输出编辑了初始问题。Do var db=new quest_geralEntities();在“GetLocalidades”方法中。
@(
Html.Kendo().Grid((IEnumerable<LocalidadeViewModel>) ViewBag.localidades)
.Name("grid")
)