2012-06-14 39 views
1

我想返回我的ActionResult在新頁面上顯示?我想返回一個新的頁面上顯示的ActionResult?

下面的這個調用是我唯一沒有能夠在新頁面上顯示的調用嗎?

任何人都可以告訴我要添加什麼來獲得這個權利,我已經使用Window.open與按鈕,但現在我有一個RedirectToAction。

這就是我想要顯示的新頁/窗口上的呼叫:

return RedirectToAction("Print", new { id = contractInstance.SalesContractId }); 

我有按鈕已與此代碼這樣:

window.open('Contract/Print/' + $(this).attr('id')); 

打印的ActionResult看起來如下:

public ActionResult Print(int id) // sales contract Id 
     { 
      ParameterFields paramFields = CreateParameterFields(id); // pass the id of the contract 
      // Save the report run details 
      Guid reportRunId; 
      SaveReportRunDetails(paramFields, out reportRunId);    

      try 
      { 

       <<< Print code >>> 
//Open a new page on this return would also be a good answer :)!!!!!!! 
       return File(arrStream, "application/pdf"); 
      } 
      catch (Exception err) 
      { 
       ViewBag.ErrorMessage = err.Message; 
       return RedirectToAction("Edit", new { id = id, error = err.Message }); 
      } 
     } 
+0

什麼不起作用...? – gdoron

+0

每一件事情都在工作,但我希望我在新的頁面或選項卡上打印,我如何才能在新頁面上顯示RedirectToAction? – Pomster

+0

類似於:return RedirectToAction(window.open(「Edit」,new {id = id,error = err.Message})); – Pomster

回答

2

如何從視圖中進行打印操作?它只是一個超鏈接@Html.ActionLink("Print", "Print")

.NET無法告訴您的瀏覽器從服務器打開一個新窗口,即通過HTML標記或JavaScript調用(例如Window.Open)完成客戶端。在新頁面中打開鏈接的最簡單方法是在HTML上指定目標屬性。使用ActionLink的助手,你的語法是:

@Html.ActionLink("Print", "Print", "Contract", new{id = Model.SalesContractId}, new {target = "_blank"}) 

這應該呈現這樣的事情:

<a href="/Contract/Print/4" target="_blank">Print</a> 
-1

您可以嘗試

Response.Write("<script type='text/javascript'> 
        window.open('YourViewName', '_blank'); 
       </script>"); 

感謝 Subraatam

按照控制器動作
+1

請更好地解釋你的解決方案是如何工作的 – niyou

相關問題