我试图在我的MVc 4.0项目中绑定Kendo Listview,但我无法绑定Listview . 没有错误,但listview div显示为空 . 我不知道事情出了什么问题 . 我的代码是:
查看页面::
@{
ViewBag.Title = "Courses";
}
@using Kendo.Mvc.UI
@model K_SampleProject.Models.CourseModel
<h2>Courses</h2>
<div class="bodywrap">
<div class="CommonClass" style="padding-bottom: 3%;"><a href="/Home/Registration">Back</a></div>
<div class="CommonClass">
@( Html.Kendo().ListView(Model.CourseList)
.Name("listView")
.TagName("div")
.ClientTemplateId("template")
.DataSource(datasource => datasource
.Model(model =>
{
//The unique identifier (primary key) of the model is the ProductID property
model.Id(p => p.pkCourseId);
// Declare a model field and optionally specify its default value (used when a new model instance is created)
model.Field(p => p.CourseName).DefaultValue("N/A");
// Declare a model field and make it readonly
model.Field(p => p.Fee).Editable(false);
})
)
.Pageable()
)
</div>
</div>
<script type="text/x-kendo-tmpl" id="template">
<div class="product">
<h3>#:CourseName#</h3>
<p>#:kendo.toString(Fee, "c")#</p>
</div>
</script>
型号::
public class CourseModel
{
public List<CourseListModel> CourseList { get; set; }
public int? CourseID { get; set; }
public string CourseName { get; set; }
public int? FEE { get; set; }
}
以下是我的注册服务:
public class RegistrationService
{
public List<CourseListModel> GetCourseDetail()
{
using (testEntities objContext = new testEntities())
{
return objContext.tbl_Courses.Select(p => new CourseListModel
{
CourseName = p.CourseName,
Fee = p.Fee,
pkCourseId = p.pkCourseId
}).ToList();
}
}
}
控制器::
public ActionResult Courses()
{
RegistrationService ObjService = new RegistrationService();
CourseModel Model = new CourseModel();
Model.CourseList = ObjService.GetCourseDetail();
return View(Model);
}
我已经使用Model.CouseList对列表视图进行了绑定,当页面加载时,它会被填充 . 因此,还需要在数据源中给出READ事件,如kendo ListView演示文档中所示,还有Link . 我完全混淆了它的约束力 . 我也检查了模板,但它与剑道中的相同documentation
1 回答
Kendo ListView要求您返回DataSourceResult . 因此,在listView中向数据源添加一个Read()并让它调用此操作: