【问题标题】:Concatenate fields in Grid using Kendo UI asp.net mvc使用 Kendo UI asp.net mvc 连接 Grid 中的字段
【发布时间】:2015-10-07 23:38:42
【问题描述】:

我是使用 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."}

【问题讨论】:

    标签: asp.net-mvc-4 visual-studio-2013 kendo-grid kendo-ui-mvc


    【解决方案1】:

    您可以利用行模板功能来实现它。请在下面找到sn-p,完整的演示可以看到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()
    

    )

    【讨论】:

      【解决方案2】:

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

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

      然后你可以将Name绑定到网格,像这样

      columns.Bound(p =&gt; p.Name);

      你应该很高兴......

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-09-14
        • 1970-01-01
        • 2016-06-23
        • 1970-01-01
        • 2016-10-30
        • 1970-01-01
        相关资源
        最近更新 更多