0

Catalog次のように、Razor ビュー ( /Productビュー)で Telerik asp.net MVC 3 ファイル コントロールを使用しています。

@(Html.Telerik().Upload()
    .Name("orderImageAtachment")
    .Async(async => async.Save("Save", "Catalog").AutoUpload(true))
    .ClientEvents(events => events
        .OnSuccess("ItemImageOnSuccess")
        .OnError("ItemImageOnError")
    )
)

私はこのようなものを作成しましたActionResult:

 public ActionResult Save(IEnumerable<HttpPostedFileBase> orderImageAtachment, string CompID)
        {
            // The Name of the Upload component is "attachments" 
            foreach (var file in orderImageAtachment)
            {
                // Some browsers send file names with full path. This needs to be stripped.
                var fileName = Path.GetFileName(file.FileName);
                var physicalPath = Path.Combine(Server.MapPath("~/Content/Docs"), fileName);

                // The files are not actually saved in this demo
                file.SaveAs(physicalPath);
            }
            // Return an empty string to signify success
            return Content("");
        }

クライアント側の機能は次のようになります。

  function onSuccess(e) {
        // Array with information about the uploaded files
        var files = e.files;

        if (e.operation == "upload") {
            alert("Successfully uploaded " + files.length + " files");
        }
    }


    function onError(e) {

        alert('Error in file upload');
        // Array with information about the uploaded files
        var files = e.files;

        if (e.operation == "upload") {
            alert("Failed to uploaded " + files.length + " files");
        }

        // Suppress the default error message
        e.preventDefault();
    }

ブラウズウィンドウを開く選択ボタンを取得します。しかし、それをクリックしても何も起こりません....何が悪いのかわかりません。web.config に何かを追加する必要がありますか? 提案してください。

4

1 に答える 1

0

どの時点で機能していないのか少し混乱していますが、コントローラーのアクションにヒットしていないと思います。かなり小さなファイルを試していることを確認してください。デフォルトの制限は 4 MB です。

また、アクションの署名がSave、アップロードの .xml で指定したルートと一致していないようですasync.Save(...)。文字列なので問題になるかどうかはわかりませんが、保存アクションのパラメーターを削除してみてCompIDください (少なくともスニペットで使用されているようには見えません)。

使用しているブラウザでフィドラーまたは開発者ツールを使用して、404エラーが偶然発生しているかどうかを確認してみてください。

于 2012-06-26T20:19:07.723 に答える