嗨,我是MVC3 Razor的新手。MVC Razor Var数据
我试图显示数据库表中的值。
在控制器我写的代码为
var test1 = from ed in db.EmpDetails
join dp in db.Departments on ed.EmpDept equals dp.DeptId
select new
{
EmpId = ed.EmpId,
EmpName = ed.EmpName,
EmpDesignation = ed.EmpDesignation,
EmpSalary = ed.EmpSalary,
EmpUserName =ed.EmpUserName,
EmpDept =ed.EmpDept,
deptName = dp.deptName
};
ViewBag.test = test1;
,并在视图
@foreach (var tm in ViewBag.test)
{
string abc [email protected];
// and the logic
}
Here i am getting all the value in the "tm" variable. But when i try to get the particular value of EmpName in a string it is showing the error as "'object' does not contain a definition for 'EmpName'".
请帮我解决这个错误。 谢谢 san
为什么不直接使用强类型的模型? – iwayneo 2011-06-10 07:24:08