【发布时间】:2013-02-26 14:07:57
【问题描述】:
是的,我想创建一个List<T>,而我的 T 是用户定义的数据类型,即 POCO 类,例如UserProfile.
为什么:我正在使用MvcJqGrid,我想编写一个通用代码来创建 Json 数据,所以在运行时我会知道我需要从哪个类(表)中获取数据。
我的代码
public ActionResult TestGrid()
{
string spname = Request.Params["storedprocedurename"]; //spname = UserProfile
// i get this from the post data of MvcJqGrid i.e. user when create a jqgrid, in
// a view defines the table/spname from where data gets loaded in grid.
MyEntities _context = new MYEntities();
List<UserProfile> userProfiles = _context.UserProfiles.ToList<UserProfile>();
// here some code to create a json data and return
}
所以我在这里硬编码了这个 UserProfile,如果我在 Request.params 中得到 RoleMaster(例如)怎么办 那么我该如何实现呢。
配置详情
entityFramework Version=5.0.0.0 数据库优先方法
mvc 4
MvcJqGrid 1.0.9
.net 框架 4.5
【问题讨论】:
-
您可能会从一个相关问题中获得更多信息,其中一个通用函数在运行时被参数化:stackoverflow.com/questions/13397286/…
标签: entity-framework list generics asp.net-mvc-4 mvcjqgrid