【发布时间】:2013-06-14 11:39:39
【问题描述】:
我正在从使用 linq 到 sql 的 theee 表中获取结果,但我无法使用视图中的值,因为我是 mvc 新手,我该如何做到这一点
这是我的控制器代码:
public ActionResult Grid()
{
ViewBag.Message = "Your Grid page.";
bc_limsEntities objbc_limsDBContext = new bc_limsEntities();
var result = from b in objbc_limsDBContext.dc_tpatient_bookingm
join d in objbc_limsDBContext.dc_tpatient_bookingd on b.bookingid equals d.bookingid
join t in objbc_limsDBContext.dc_tp_test on d.testid equals t.TestId
where b.bookingid == 41239 && d.ProcessID == 0006 && t.SubdepartmentId == 16
select new {b.bookingid,
d.bookingdid,
d.testid,
t.Test_Name,
t.procedureid,
t.ClinicalUse,
t.AutomatedText};
ViewBag.Result = result.ToList();
return View(result);
}
我正在这样做:
@foreach(var item in ViewBag.Result)
{
<h1>@item</h1>
}
【问题讨论】:
-
您的数据库上下文没有得到处理。将其包裹在
using子句中。 -
@asawyer 说得对,我认为
标签: sql-server asp.net-mvc linq razor