【发布时间】:2011-09-12 06:53:52
【问题描述】:
嗨,我是 MVC3 Razor 的新手。
我试图显示数据库表中的值。
在控制器中我将代码编写为
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 =@tm.EmpName;
// 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'".
请帮我解决这个错误。 谢谢 桑
【问题讨论】:
-
为什么不直接使用强类型模型?
标签: linq asp.net-mvc-3 razor var