【问题标题】:Unable to bind Kendo ListView in MVC无法在 MVC 中绑定 Kendo ListView
【发布时间】:2014-09-29 07:23:45
【问题描述】:

我试图在我的 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

【问题讨论】:

    标签: c# .net kendo-ui telerik kendo-asp.net-mvc


    【解决方案1】:

    Kendo ListView 要求您返回一个 DataSourceResult。因此,将 Read() 添加到 listView 中的数据源并让它调用此操作:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多