1

我是使用 Kendo-UI 并尝试将数据从实体加载到网格的 ASP.NET MVC 的新手。有没有办法连接列中的两个字段?

@(Html.Kendo().Grid(Model)
.Name("Grid")
.Columns(columns =>
        {
            columns.Bound(p => p.employeeId).Title("ID");
            columns.Bound(p => p.firstname +" "+p.lastname).Title("Name");               
        })
        .Pageable()
        .Sortable()
        .Scrollable(scr=>scr.Height(430))
        .Filterable()
        .DataSource(datasource => datasource
        .Ajax()
        .PageSize(20)
        .ServerOperation(false)
)

我尝试了此解决方案,但出现错误。

{"Bound columns require a field or property access expression."}
4

2 回答 2

1

You can make use of the row template function to achieve it. Please find the snippet below and full demo can be seen here.

@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.EmployeeViewModel>()
.Name("grid")
.HtmlAttributes(new { style = "width: 750px;height:430px;" })
.Columns(columns =>
{
    columns.Template(e => { }).ClientTemplate(" ").Width(140).Title("Picture");
    columns.Bound(e => e.Title).Width(400).Title("Details");
    columns.Bound(e=> e.EmployeeID).Title("ID");
})
.ClientRowTemplate(
    "<tr data-uid='#: uid #'>" +
        "<td class='photo'>" +
           "<img src='" + Url.Content("~/Content/web/Employees/") +"#:data.EmployeeID#.jpg' alt='#: data.EmployeeID #' />" +
        "</td>" +
        "<td class='details'>" +
            "<span class='title'>#: Title #</span>" +
            "<span class='description'>Name : #: FirstName# #: LastName#</span>" +
            "<span class='description'>Country : #: Country# </span>" +
        "</td>" +
        "<td class='employeeID'>" +
            "#: EmployeeID #" +
        "</td>" +
     "</tr>"      
)

.Scrollable()

)

于 2015-04-23T06:42:13.730 回答
1

您可以实现您想要做的事情的一种方法是在您的模型中创建一个 Name 属性,其中只有一个连接名字和姓氏的 getter,就像这样

public string Name { get { return string.Format("{0} {1}", firstname, lastname); } }

然后您可以将名称绑定到网格,如下所示

columns.Bound(p => p.Name);

你应该很高兴去...

于 2015-10-07T15:38:42.650 回答