1

我有一个视图用于显示我的搜索项的结果。这是它的控制器:

[HttpPost]
public ActionResult EvaluatingReport(FormCollection frm)
{
 string empType = frm["empType"].ToString();
 int totalMonth = 3;
 int mon = DateTime.Now.Month;
 int yr = DateTime.Now.Year;
 string Curdate = mon + "/" + yr;
 DateTime date = new DateTime();
 var result = (from e in context.tblEmployees
 join p in context.tblEmployee_Position on e.PositionIDF equals p.PositionID
 select new EvaluateEmployee
  {
    ID = e.Code,
    IDCard = e.IDCard,
    Name = e.NameEng,
    DOB = e.DOB,
    Position = p.Position,
    Sex = e.Sex,
    StartDate = e.StartDate
}).ToList();
  result = result.Where(((s => mon - int.Parse(s.StartDate.Substring(3, 2).ToString()) == totalMonth && yr -int.Parse(s.StartDate.Substring(6, 4).ToString()) ==  totalYear))).ToList();
  ViewData["EmployeeType"] = result;
  return View();
}

我通过循环在视图中显示了内容, ViewData["EmployeeType"]并且还包括了一个Print标签:

<script language="javascript" type="text/javascript">
  function printChart() {
    var URL = "EvaluatingReport";
    var W = window.open(URL);
    W.window.print(); 
  }
  function printPage(sURL) {
    var oHiddFrame = document.createElement("iframe");
    oHiddFrame.src = sURL;
    oHiddFrame.style.visibility = "hidden";
    oHiddFrame.style.position = "fixed";
    oHiddFrame.style.right = "0";
    oHiddFrame.style.bottom = "0";
    document.body.appendChild(oHiddFrame);
    oHiddFrame.contentWindow.onload = oHiddFrame.contentWindow.print;
    oHiddFrame.contentWindow.onafterprint = function () {          
    document.body.removeChild(oHiddFrame); };
  }   
  </script> 
  <span onclick="printPage('/Report/PrintEvaluatingReport');" style="cursor:pointer;text-decoration:none;color:#0000ff;"> 
     <img src="../../Content/images/Print.png" width="35px;" alt="print" style="position:relative;top:6px;"/> 
      &nbsp; Print Report
  </span>

我使用函数printPage('/Report/PrintEvaluatingReport')来加载带有操作的打印对话框PrintEvaluatingReport。所以我想把我拥有的对象EvaluatingReport带到行动PrintEvaluatingReport中。

谁能告诉我我该怎么做?

提前致谢。

4

2 回答 2

1

您可以为此使用会话变量!

private EmployeeType Result
{
    get { return (EmployeeType)this.Session["Result"]; }
    set
    {
        this.Session["Result"] = value;
    }
}

[HttpPost]
public ActionResult EvaluatingReport(FormCollection frm)
{
   .
   .
   .    
   // Store in Session
   this.Result = result;

   return View();
}

public ActionResult PrintEvaluatingReport()
{
   var employeeType = this.Result;
   .
   .
   .

}
于 2012-08-11T01:37:13.417 回答
1

你可以使用TempData["EmployeeType"]

[HttpPost]
public ActionResult EvaluatingReport(FormCollection frm)
{
    string empType = frm["empType"].ToString();
    int totalMonth = 3;
    int mon = DateTime.Now.Month;
    int yr = DateTime.Now.Year;
    string Curdate = mon + "/" + yr;
    DateTime date = new DateTime();
    var result = (from e in context.tblEmployees
    join p in context.tblEmployee_Position on e.PositionIDF equals p.PositionID
    select new EvaluateEmployee
    {
       ID = e.Code,
       IDCard = e.IDCard,
       Name = e.NameEng,
       DOB = e.DOB,
       Position = p.Position,
       Sex = e.Sex,
       StartDate = e.StartDate
   }).ToList();
   result = result.Where(((s => mon - int.Parse(s.StartDate.Substring(3, 2).ToString()) == totalMonth && yr -int.Parse(s.StartDate.Substring(6, 4).ToString()) ==  totalYear))).ToList();
   ViewData["EmployeeType"] = result;


   // Store in TempData to be read by PrintEvaluatingReport
   TempData["EmployeeType"] = result;

   return View();
}

public ActionResult PrintEvaluatingReport()
{
   var employeeType = TempData["EmployeeType"] as EmployeeType;
   // do stuff
   return View();
}
于 2012-08-11T01:38:03.260 回答