我想在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