我试图为 MVC 实现 Kendo UI 的 Listview 控件。我正在尝试将列表视图与我的模型绑定,但出现此错误:
“CS1977:不能使用 lambda 表达式作为动态分派操作的参数,除非先将其转换为委托或表达式树类型”
我已经检查了有关 stackoverflow 的其他一些问题,但出现了相同的错误,但我无法知道此错误的原因,因为这是 kendo 语法,据我所知,我的代码没有任何问题。
错误在这一行::.DataSource(ds => 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);
}