简体   繁体   English

无法在MVC中绑定Kendo ListView

[英]Unable to bind Kendo ListView in MVC

I am trying to bind Kendo Listview in my MVC 4.0 project, but I am unable to bind the Listview. 我试图在我的MVC 4.0项目中绑定Kendo Listview,但是我无法绑定Listview。 There is no error but The listview div is shown to be empty. 没有错误,但listview div显示为空。 I do not know where the things have gone wrong.Below is my code: 我不知道哪里出了问题,下面是我的代码:

View Page 查看页面

@{
    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>

Model 模型

public class CourseModel
{
    public List<CourseListModel> CourseList { get; set; }
    public int? CourseID { get; set; }
    public string CourseName { get; set; }
    public int? FEE { get; set; }
}

Below is my Registration Service: 以下是我的注册服务:

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();
        }
    }
}

Controller 调节器

  public ActionResult Courses()
  {
      RegistrationService ObjService = new RegistrationService();
      CourseModel Model = new CourseModel();
      Model.CourseList = ObjService.GetCourseDetail();
      return View(Model);
  }

I have already binded the list view with Model.CouseList which is filled when the page loads.So,is it also necessary to give READ Event in the datasource as shown in documentation of kendo ListView demo and Also this Link . 我已经将列表视图与Model.CouseList绑定在一起,该页面加载时将填充该Model.CouseList。因此,是否还需要在数据源中提供READ Event,如kendo ListView演示文档以及此Link中所示

I'm totally confused with it's binding. 我对它的绑定感到困惑。 I have checked the template also but it is same as it is in kendo documentation 我也检查了模板,但它与Kendo 文档中的模板相同

Kendo ListView's require you to return a DataSourceResult. Kendo ListView要求您返回一个DataSourceResult。 So add a Read() to the datasource in your listView and have it call this action: 因此,将Read()添加到listView中的数据源,并使其调用此操作:

public ActionResult GetCourses([DataSourceRequest] DataSourceRequest request)
{
    RegistrationService ObjService = new RegistrationService();
    return ObjService.GetCourseDetail().ToDataSourceResult(request);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM