我想在MVC中设计一个解决方案,其中一个类的字符串表示形式被传递给控制器,然后应该与所有的控制器构建一个网格在DB中属于该类的数据。 (我使用ORM将类映射到表)。从类型的字符串表示动态生成一个特定类型的Enumerable对象
//A method in the Model that populates the Item Property
foreach (MethodInfo method in sDRMethods)
{
if (method.Name.Contains(_domainTable))
{
Items = method.Invoke(repositoryObject, null);
break;
}
}
//View uses this Items property of the Model to populate the grid.
public object Items;
//_domainTable is the name of the table/class (in string format).
//repositoryObject is the object that has methods to return IEnumerable<class> collection object of each type.
我遇到的问题是我不知道如何在我的视图中投射“Items”属性来遍历它并构建网格。
我曾尝试使用“http://mvcsharp.wordpress.com/2010/02/11/building-a-data-grid-in-asp-net-mvc/”,但通用扩展方法期望知道它应该使用的特定类型。我倾向于使用MVC,但它看起来像我不能轻易地有这个工作(这是很难相信)。
是否有更多的代码没有发布但正在使用? – jfar 2010-10-15 12:19:12
是的,但我不认为这很重要。缺少的代码是执行上述代码的方法的“调用”。和这样做的观点: – Aaron 2010-10-18 11:25:21
Switch(_domainTable){case“systemLookUpTable1”:return(IEnumerable)Model.Items; ....}我真的不喜欢这个视图中的switch语句! –
Aaron
2010-10-18 11:27:26