【发布时间】:2014-06-13 06:27:42
【问题描述】:
我最近开始将 Kendo UI 整合到我的项目中。我有一个强类型视图,并希望将 Kendo 网格绑定到视图上的适当视图模型:
@ModelType IEnumerable(Of IMS_2.Models.expenseclaims)
@Code
ViewData("Title") = "Index"
End Code
<h2>Index</h2>
<div>
@code
Html.Kendo().Grid(Model).Name("ExpenseClaims") _
.Columns(Sub(c)
c.Bound(Function(x) x.ClaimDate).Width(140)
c.Bound(Function(x) x.Title).Width(190)
c.Bound(Function(x) x.Company)
End Sub)
end code
</div>
代码在服务器上无异常执行,在客户端也无 javascript 错误。对渲染源的检查显示没有提到网格:
<h2>Index</h2>
<div>
</div>
<hr />
<footer>
...等
我的代码是(我认为)我在 c# 中看到的其他示例的直接翻译(参见 http://telerikhelper.net/2012/10/26/using-kendo-grid-in-asp-net-mvc-4-0/)
Expenseclaims 由 EF 模板生成,定义为:
Partial Public Class expenseclaims
Public Property id As Long
Public Property Title As String
Public Property ClaimDate As Nullable(Of Date)
Public Property Creator As Nullable(Of Long)
Public Property Company As Long
Public Property AdvanceOffset As Nullable(Of Decimal)
Public Overridable Property expenselines As ICollection(Of expenselines) = New HashSet(Of expenselines)
Public Overridable Property companies As companies
End Class
控制器代码为:
Public Class ExpenseController
Inherits System.Web.Mvc.Controller
Private db As New IMSEntities
' GET: /Expense/
Function Index() As ActionResult
Return View(db.expenseclaims.ToList())
End Function
这是我难过的地方...任何帮助表示感谢。
【问题讨论】:
-
我认为我们在这里唯一缺少的(代码方面)是您的 Controller 方法。它应该是公共的 ActionResult Index()....,它包含 DataClasses1DataContext,它依次通过 return View(context.Persons) 行传递“填充”模型。我知道您的代码会略有不同,但您可以在 VB.NET 代码中的“返回”行设置一个断点,以查看是否有任何数据正在传递。
-
谢谢 - 是的 - 在网格语句上设置断点使我可以看到“模型”包含 221 个数据项。已将控制器代码添加到问题中。
-
您是否尝试过删除返回方法中的 .ToList() 部分?也许它没有正确传递上下文?
-
这似乎没有任何区别 - 尽管我无法再看到模型中的 221 个数据项(模型直接引用 EF 实体而不是项目列表)。无论哪种方式,网格仍然没有呈现。
标签: asp.net-mvc vb.net kendo-ui kendo-grid kendo-asp.net-mvc