[英]Concatenate fields in Grid using Kendo UI asp.net mvc
I'm new to ASP.NET MVC using Kendo-UI and trying to load data from entity to Grid. 我是使用Kendo-UI并尝试将数据从实体加载到Grid的ASP.NET MVC的新手。 is there a way to concatenate two fields in a column? 有没有一种方法来连接列中的两个字段?
@(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)
)
I tried this solution but I get an error. 我尝试了此解决方案,但出现错误。
{"Bound columns require a field or property access expression."}
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()
) )
One of the ways you can achieve what you are trying to do is by creating a Name property in your Model with just a getter which concatenates firstname and lastname, like this 实现目标的一种方法是通过在模型中创建一个Name属性,而只需一个将名和姓连接在一起的吸气剂,如下所示
public string Name { get { return string.Format("{0} {1}", firstname, lastname); } }
Then you can bind the Name to the grid, like this 然后,您可以将Name绑定到网格,就像这样
columns.Bound(p => p.Name);
You should be good to go... 你应该很好...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.