1

我有以下观点:

<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);
}
4

1 回答 1

0

Action Method 参数自动映射 Request.Form。也就是说,如果您的表中有表单字段,您将只能使您的 DataTable 参数工作(具有值)。

由于您不想让用户编辑数据,我建议您使用隐藏字段。您可以“手动” ( <input type="hidden" />) 或使用 MVC Html 帮助程序 ( @Html.HiddenFor()) 来完成它们。

于 2013-09-08T08:25:36.773 回答