場景:有三個視圖(Razor)名爲「InvoiceBill」,「Index」,「Create」。在MVC3和Razor中從單個動作返回多個視圖
- 創建視圖包含用於輸入發票數據的表單頁面。
- 索引頁面包含所有當前日期發票賬單的列表。
- InvoiceBill包含基於此鏈接生成Excel文檔(作爲發票報告)的代碼(http://forums.asp.net/t/1711971.aspx/1)。
一旦我提交表單(創建視圖),它可以將表單數據發佈到數據庫(使用EF)。插入數據後,它返回索引頁面。
但現在我需要在調用索引頁之前調用「InvoiceBill」視圖。
[HttpPost]
public ActionResult Create(FormCollection collection, InvoiceViewModel INVViewModel)
{
if ((collection != null) && (this.ModelState.IsValid))
{
salesOrder.AccountNumber = INVViewModel.AccountNumber;
salesOrder.BillToAddressID = INVViewModel.BillToAddressID;
salesOrder.Comment = INVViewModel.Comment;
salesOrder.ContactID = INVViewModel.ContactID;
.
.
.
.
int sID = Using<CreateSalesOrder>().Execute(0, salesOrder);
***** From here i need to call the InvoiceBill page. Or guide me any other good way to achieve this
return RedirectToAction("Index");
}
}
現在我正在通過一些解決方法實現此目標。但我覺得這不好。請指導我如何以正確的方式實現這一目標? 感謝
編輯:
public ActionResult PrintInvoice(int id)
{
InvoiceReportViewModel invoiceReport = new InvoiceReportViewModel();
var soToView = Using<GetSalesOrders>().ExecuteForReport(id);
invoiceReport.InvoiceBillName = "Invoice" + id.ToString();
invoiceReport.CustomerName = soToView.Customer.Name;
invoiceReport.SalesOrderNumber = soToView.SalesOrderNumber;
.
.
.
.
return View(invoiceReport);
}
的InvoiceReport.cshtml
@model eItemBox.Web.Models.InvoiceReportViewModel
@{
Layout = null;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment; filename=" + Model.InvoiceBillName);
//Content-Disposition is defined in RFC-2183
}
<Worksheet ss:Name="MyInvoice">
.
.
.
</Workbook>
你想返回多個視圖或不同的視圖? – saintedlama
不同意見 – getmk