0

ASP.NET MVC で、投稿を介してファイルをダウンロードし、JSON データを送信しようとしています。この JSON データは、knockout.js を介してページに表示されるデータのフィルターです。基準オブジェクトは常に null です。javascriptまたはフォーム投稿を介して投稿データを送信することにより、ファイルをダウンロードするにはどうすればよいですか? GET を使用して ajax のダウンロードを完了しましたが、投稿する必要がある配列などの余分なデータがあります。

<form method="POST" action="@Model.ExportUrl" >
    <input type="hidden" name="criteria" data-bind="value: ko.toJSON(data())"  />
    <button class="btn"><i class="icon-download-alt"></i> Export</button>
</form>

リクエスト

Request URL:http://localhost:2222/members/eventteams/export?eventId=8998
Request Method:POST
Status Code:500 Internal Server Error
Request Headersview source
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Content-Length:128
Content-Type:application/x-www-form-urlencoded
Host:localhost:2222
Origin:http://localhost:2222
Referer:http://localhost:2222/members
User-Agent:Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36
Query String Parametersview sourceview URL encoded
eventId:8998
Form Dataview sourceview URL encoded
criteria:{"page":1,"pageSize":"100","sortOrder":"Team.Name","sortDirection":"ASC"}

コントローラ

[HttpPost]
public virtual ActionResult Export(int eventId, DivisionTeamsTableCriteria criteria)
{
4

2 に答える 2

0

knockout.js を使用して、非常にうまく機能するこのカスタム バインディングを作成しました。

ko.bindingHandlers.download = {
        init: function (element, valueAccessor) {

            var value = ko.utils.unwrapObservable(valueAccessor()),
                id = 'download-iframe-container',
                iframe;

            $(element).unbind('click').bind('click', function () {

                iframe = document.getElementById(id);

                if (!iframe) {
                    iframe = document.createElement("iframe");
                    iframe.id = id;
                    iframe.style.display = "none";
                }

                if (value.data) {
                    iframe.src = value.url + (value.url.indexOf('?') > 0 ? '&' : '?') + $.param(ko.mapping.toJS(value.data));
                } else {
                    iframe.src = value.url;
                }

                document.body.appendChild(iframe);

                return false;
            });
        }
    };
于 2013-08-08T03:48:10.173 に答える
0

このようなフォームを iframe に投稿してみることができ ます。 iframe に投稿するにはどうすればよいですか?

そして、iframe asp.net ページで、File to response を次のように 書き込みます Write to CSV file and export it?

  • Iframe は 1x1 ピクセルにすることができます
于 2013-08-07T23:54:47.560 に答える