I am using Telerik’s MVC Grid in my project which really is good. Unfortunately I am stuck at last.. The problem is that I want to show a collection inside a column. The collection is a property of my user model. Here is the sample code:
{...}
.Columns(columns =>
{
columns.Bound(u => u.Id).Title("No.").Width(100);
columns.Bound(u => u.UserName).Title("User Name");
columns.Bound(u => u.CompanyName).Title("Company Adı");
columns.Template(u =>
{
foreach(var item in u.Roles)
{
}
}).Title("Roller");
columns.Command(commands =>
{
commands.Custom("viewDetails")
.Text("Detail")
.DataRouteValues(route => route.Add(o => o.Id).RouteKey("UserAccountId"))
.Ajax(false)
.Action("UserAccountRead", "Account");
commands.Delete().ButtonType(GridButtonType.ImageAndText);
})
.Width(200);
})
.Sortable()
.Pageable(paging => paging.PageSize(10))
.Localizable("en-EN")
)
{...}
In the foreach loop I’ve tried many things to display user roles, but haven’t succeed.
@item.Name
I Got : Error: Only assignment, call, increment, decrement and new object expressions can be used as a statement
@:<text>@item.Name</text>
I Got: ; required
And so on… What should I write as a statement for just making the column to show user roles?
You can add a ReadOnly property to your model which returns a simplified formatted text for you. for example you :