I have an MVC3 app using the telerik’s grid control. I’m populating the grid fine but my model that i use has an array inside of it that needs to be displayed in a single column. Heres my model
public class MyModel
{
public string parentName {get; set;}
public string[] childrenNames { get; set; }
}
Now populate my class with data in the controller:
public ActionResult Index()
{
var loo = new MyModel[2];
loo[0] = new MyModel();
loo[0].parentName = "Troy";
loo[0].childrenNames[0] = "chris";
loo[0].childrenNames[1] = "tony";
loo[1] = new MyModel();
loo[1].parentName = "Mike";
loo[1].childrenNames[0] = "lee";
loo[1].childrenNames[1] = "mary";
IEnumerable<MyModel> model = loo;
return View(model);
}
Now my childrenNames array can and will have more than one entry, but I need the childrenNames to be combined into one value seperated by commas and displayed in my grid:
@model IEnumerable<MyModel>
@(Html.Telerik().Grid(Model)
.Columns(columns =>
{
columns.Bound(o => o.parentName).Width(100).Title("Parent");
columns.Bound(o => o.childrenNamesCombined).Width(250).Title("Kids");
}
How do I do that?
You can’t have an array as a single column
You should make it string in the Model, or have another property with the joined array: