我想用Telerik MVC与动态ExpandoObjects的集合。Telerik MVC网格列表ExpandoObject
控制器是:
[GridAction]
public ActionResult TestDiario()
{
var result = new List<dynamic>();
dynamic diarioModel = new ExpandoObject();
var dictionary = (IDictionary<string, object>)diarioModel;
dictionary.Add("ID", 1);
dictionary.Add("AlunoID", 12781);
dictionary.Add("DAY05CLASS1", true);
dictionary.Add("DAY05CLASS2", true);
dictionary.Add("DAY07CLASS1", true);
dictionary.Add("DAY08CLASS1", true);
result.Add(diarioModel);
return View(result);
}
的观点是:
@using Telerik.Web.Mvc.UI
@model IEnumerable<dynamic>
@{
ViewBag.Title = "TestDiario";
}
@(Html.Telerik().Grid(Model).Name("Grid")
.DataKeys(dataKeys => dataKeys.Add("ID"))
.Columns(columns =>
{
columns.Bound("MatAnoID").Visible(true);
columns.Bound("AlunoID");
columns.Bound("NroClasse");
columns.Bound("Aluno");
var dictionary = (IDictionary<string, object>)Model;
foreach (var property in (IDictionary<String, Object>)dictionary)
{
if (property.Key.ToString().Remove(3) == "DAY")
{
columns.Bound(property.Key);
}
}
})
.Pageable()
.Sortable()
.Groupable()
.Filterable()
)
循环的foreach得到一天字符串启动的动态领域。
当我运行的项目出现下列错误:
{ “是不是可以转换一个类型的对象 'System.Collections.Generic.List 1[System.Object]' to type 'System.Collections.Generic.IDictionary
2 System.String,System.Object的]'。”}
有没有穿过田野使用动态物体与Telerik的MVC控制与循环的方法吗?
谢谢你,它的工作原理! – user1822331