我有這樣一個觀點:MVC列表檢查和選擇操作,然後到CSV文件
@model IEnumerable<VectorCheck.Models.Invoice>
@{
ViewBag.Title = "Exportable Invoices";
}
<script src="../../Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-ui-1.8.16.min.js" type="text/javascript"></script>
<script src="../../Scripts/Views/Export/index.js" type="text/javascript"></script
<header class="header">
<div class="headerText">
<h1>Exportable Invoices</h1>
</div>
</header>
@using (Html.BeginForm("Export", "Export")) {
<table>
<tr class="mainheader">
<th>Invoice Number</th>
<th>Date</th>
<th>Organisation</th>
<th>Total (Excl GST)</th>
<th>Status</th>
<th>Exported Date</th>
<th>
<select id="expenseSelect"></select>
<input type="submit" id="btnexport" value="Export" />
</th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.InvoiceNumber)
</td>
<td>
@Html.DisplayFor(modelItem => item.InvoiceDate, "{0:D}")
</td>
<td>
@Html.DisplayFor(modelItem => item.Organisation.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.TotalExcludingGst)
</td>
<td>
@Html.DisplayFor(modelItem => item.Status)
</td>
<td>
@Html.DisplayFor(modelItem => item.ExportedDateTime)
</td>
<td class="centered">
<input type="checkbox" class="exportcheckbox" [email protected] />
</td>
</tr>
}
</table>
}
<div>
@Html.ActionLink("Back to Summary", "Index", "Invoice")
</div>
好了,看到每個複選框有着怎樣的attribrute [email protected]
。那麼我試圖找到一個行動方法的所有發票,其複選框檢查的ID。此外,我試圖獲得選擇列表的費用選擇,其中有選項添加到它的頁面加載通過jQuery的ID。我設法用jQuery實現這一點,然後用$.post
發送數據。問題出在我發送信息的文件中:
public ActionResult Export()
{
...
var csvData = _utility.GetCsvData(data);
return File(Encoding.UTF8.GetBytes(csvData), "text.csv", "invoices.csv");
}
調出保存/打開文件對話框。我被告知這不會爲jQuery Ajax調用工作,我需要使用提交發布信息。
這很好,但現在我不知道如何將選擇ID和選中複選框的ID列表發送到方法。任何人都可以告訴我該怎麼做?
從我已經被告知和體驗對話框將不會出現這樣的javascript帖子。必須提交表單或彈出的對話框不會出現。 – AnonyMouse
更新了使用隱藏的iframe的答案,因此您可以獲得下載對話框。這意味着沒有阿賈克斯壽。 – russau