我有以下观点:
<table cellpadding="0" cellspacing="0" border="0" class="display mobile_dt1" id="SearchResults">
<thead>
<tr>
@* <input type="checkbox" name="Test" onclick="SetAllCheckBoxes('PartialViewName')" *@
<th id="CHCKID" class="checkBoxClass">Check All @Html.CheckBox("checkboxall", new { @id = "checkall", @name = "StatusList" })</th>
<th>Export</th>
<th>Request ID</th>
<th id="RQSTNMSRCHID" style="display: none">@BVPConstants.RQSTNMSRCH</th>
<th id="RQSTSTTSSRCHID">@BVPConstants.RQSTSTTSSRCH</th>
<th>Strategic Initiative</th>
<th id="BSNGRPL1ID">@BVPConstants.BSNGRPL1</th>
<th id="EXCTVSPNSRID">@BVPConstants.EXCTVSPNSR</th>
<th id="RQSTCLSFNID">@BVPConstants.RQSTCLSFN</th>
<th id="BUSNDBYDTID">@BVPConstants.BUSNDBYDT</th>
<th id="CRTDBYSRCHID">@BVPConstants.CRTDBYSRCH</th>
<th id="CRTDONID">@BVPConstants.CRTDON</th>
</tr>
</thead>
<tbody>
@if (Model != null)
{
foreach (var SearchResult in Model)
{
<tr>
<td class="chck">@Html.CheckBox("checkboxall", new { @id = "check" })</td>
<td>@Html.ActionImage("", "", new { @Id = "export" }, null, null, null, "~/Content/img/ico/filePDFUpload.png", "Download")</td>
<td>@Html.ActionLink(SearchResult.RequestId.ToString(), "Edit", "BusinessRequest", new { requestId = SearchResult.RequestId }, new { @onerror = "closeLoading()", @onload = "closeLoading()", @onclick = "showLoading()" })</td>
<td>@Html.ActionLink(SearchResult.RequestName.ToString(), "Edit", "BusinessRequest", new { requestId = SearchResult.RequestId }, new { @onerror = "closeLoading()", @onload = "closeLoading()", @onclick = "showLoading()" }) </td>
<td>@SearchResult.Status</td>
<td>@SearchResult.StrategicInitiativeNumber</td>
<td>@SearchResult.BusinessGroup</td>
<td>@SearchResult.ExecutiveSponsorNumber</td>
<td>@SearchResult.RequestClassification</td>
<td>@SearchResult.BusinessNeedByDate</td>
<td>@SearchResult.CreatedBy</td>
<td>@SearchResult.CRTTs</td>
</tr>
}
}
</tbody>
</table>
我想将 SearchResults 数据表发送到以下控制器方法:
public PartialViewResult ExportToExcel(DataTable table) {
List<SearchRequestModel> srchlist = new List<SearchRequestModel>();
StringWriter stringWriter = new StringWriter();
var grid = new GridView();
grid.DataSource = table;
grid.DataBind();
Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachment; filename=Prioritization.xls");
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
grid.RenderControl(htmlTextWriter);
Response.Write(stringWriter.ToString());
Response.End();
return PartialView("_SearchHistory", srchlist);
}