Asp.net mvc 4 MVC中Kendo Listview控件的实现

Asp.net mvc 4 MVC中Kendo Listview控件的实现,asp.net-mvc-4,razor,kendo-ui,kendo-asp.net-mvc,kendo-listview,Asp.net Mvc 4,Razor,Kendo Ui,Kendo Asp.net Mvc,Kendo Listview,我试图为MVC实现剑道UI的Listview控件。我试图将列表视图与我的模型绑定,但出现以下错误: CS1977:如果不首先将lambda表达式强制转换为委托或表达式树类型,则无法将其用作动态调度操作的参数 我已经检查了stackoverflow上的一些其他问题,但我无法知道这个错误的原因,因为这是剑道语法,据我所知,我的代码没有任何错误 错误在这一行::.DataSourceds=>ds 查看页面: @{ ViewBag.Title = "Courses"; } @using Kend

我试图为MVC实现剑道UI的Listview控件。我试图将列表视图与我的模型绑定,但出现以下错误:

CS1977:如果不首先将lambda表达式强制转换为委托或表达式树类型,则无法将其用作动态调度操作的参数

我已经检查了stackoverflow上的一些其他问题,但我无法知道这个错误的原因,因为这是剑道语法,据我所知,我的代码没有任何错误

错误在这一行::.DataSourceds=>ds

查看页面:

@{
    ViewBag.Title = "Courses";
}
@using Kendo.Mvc.UI

<h2>Courses</h2>

<a href="/Home/Registration">Back</a>

<div class="bodywrap">
    <div class="CommonClass">

        @( Html.Kendo().ListView<K_SampleProject.Models.CourseModel>(Model)
          .Name("listView")
          .TagName("div")
          .ClientTemplateId("template")
          .DataSource(ds => ds
          .Model(model =>
          {
              //The unique identifier (primary key) of the model is the ProductID property
              model.Id(p => p.ProductID);

              // Declare a model field and optionally specify its default value (used when a new model instance is created)
              model.Field(p => p.ProductName).DefaultValue("N/A");

              // Declare a model field and make it readonly
              model.Field(p => p.UnitPrice).Editable(false);
          })
)
    .Pageable()
         )
    </div>
</div>


<script type="text/x-kendo-tmpl" id="template">
    <div class="product">
        <img src="@Url.Content("~/content/web/foods/")${ProductID}.jpg" alt="${ProductName} image" />
        <h3>${ProductName}</h3>
        <dl>
            <dt>Price:</dt>
            <dd>${kendo.toString(UnitPrice, "c")}</dd>
        </dl>
    </div>
</script>

Model
namespace K_SampleProject.Models
{
    public class CourseModel
    {
        public List<tbl_Courses> CourseList { get; set; }
        public string ProductID { get; set; }
        public string ProductName { get; set; }
        public string UnitPrice { get; set; }
    }
}

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

代码中的主要错误是将单个CourseModel类传递给列表,而它需要CourseModel列表。 因此,您的控制器应该如下所示:

    public ActionResult Courses()
    {
        List<CourseModel> result;
        CourseModel Model = new CourseModel();
        RegistrationService ObjService = new RegistrationService();
        Model.CourseList = ObjService.GetCourses();
        result.Add(Model);
        return View(result);
    }
我亦建议:

在视图顶部添加@model列表 如果它是PartialView而不是像索引更改那样的主视图,则返回:returnpartialViewResult;
您是否已将模型传递到此视图?您应该添加:@model K_SampleProject.Models.CourseModel并将模型传递到此视图,除非您从父视图隐式执行此操作。您传递的模型是否具有正确的K_SampleProject.Models.CourseModel类型?当我尝试将模型传递到查看页面时,它为编译错误提供了与“Kendo.Mvc.UI.Fluent.WidgetFactory.ListViewSystem.Collections.Generic.IEnumerable”匹配的最佳重载方法,该方法具有一些无效参数。我还使用模型和控制器代码更新了我的问题。请看一看。在你的对象模型中是否有一个类型为dynamic的项目潜伏在任何地方?没有。我已经再次检查过了,没有。