シナリオ:「請求書の請求書」、「索引」、「作成」という3つのビュー(レーザー)があります。MVC3&Razorの単一アクションから複数のビューを返す
- [作成]ビューには、請求書データを入力するためのフォームページがあります。
- [索引]ページには、現在のすべての日付請求書請求書のリストが含まれています。
- InvoiceBillには、このリンク(http://forums.asp.net/t/1711971.aspx/1)に基づいてExcel文書を(請求書レポートとして)生成するコードが含まれています。
フォームを送信すると(ビューの作成)、フォームデータをDBに送信できます(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");
}
}
現在、私はいくつかの回避策でこれを達成しています。しかし、私はそれが良くないと感じます。どのように私は正しい方法でこれを達成することができますか教えてください? おかげ
EDIT:
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>
上記の質問から
RenderViewToString
メソッドを使用してみてください。複数のビューまたは異なるビューを返したいですか? – saintedlama異なるビュー – getmk