我想获得在线主管的项目名称和描述
我的主管控制员:
public ActionResult SupervisorDashboard()
{
var message = TempData["message"] as string;
var name = (from s in dc.Supervisors
where s.sup_email == message
select s.sup_fname).SingleOrDefault();
ViewBag.username = name;
return View();
}
public ActionResult ViewProject()
{
var message = TempData["message"] as string;
var name = (from s in dc.Supervisors
where s.sup_email == message
select s.sup_fname).SingleOrDefault();
ViewBag.username = name;
var supid= (from s in dc.Supervisors
where s.sup_email==message
select s.sup_ID).SingleOrDefault();
var projectdata = (from s in dc.OfferedProjects
where s.FK_sup_ID==supid
select s);
return View(projectdata);
}
我的主管模特:
public class SupervisorModel
{
public Supervisor supervisor { get; set; }
public OfferedProject offerproject { get; set; }
}
我的观点:
@model IEnumerable<FYPManagment.Models.SupervisorModel>
@using FYPManagment;
@{
List<OfferedProject> projectdata = (List<OfferedProject>)ViewData["projectdata"];
ViewBag.Title = "ViewProject";
Layout = "~/Views/Shared/_SupervisorDashboarLayout.cshtml";
}
@foreach (var item in Model)
{
<tr>
<td>@item.offerproject.proj_title</td>
<td>@item.offerproject.proj_description</td>
<td>
<a href="#">Send Request</a>
</td>
</tr>
}
我的家庭控制器:
TempData["message"] = email;
//Session["user"] = email;
if (type == "supervisor")
{
return RedirectToAction("SupervisorDashboard", "Supervisor");
}
我的Supervisor Dashboard操作正在获取在线用户的电子邮件,但查看项目操作中的相同代码无效。我将非常感谢你宝贵的时间。
答案 0 :(得分:0)
您只能在TempData ONE TIME中读取密钥的值(因此名称为&#39; temp&#39;)。它一旦被读取就被删除。将TempData的使用更改为ViewBag或会话,它将起作用。