簡體   English   中英

Telerik asp.net MVC文件上傳控件

[英]Telerik asp.net MVC Fileupload control

我在Razor視圖( Catalog / 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中添加一些內容嗎? 請提出建議。

我有點困惑,這時它不起作用,但是我假設它沒有在您的控制器中起作用。 我會確保您嘗試的文件非常小,默認限制為4mb。

而且看起來您的“ Save操作”的簽名與您在上傳的async.Save(...)中給出的路由不匹配。 我不確定這是否重要,因為它是一個字符串,但是您可以嘗試刪除Save操作的CompID參數(至少看起來與代碼段中使用的參數不同)。

無論您使用哪種瀏覽器,我都會嘗試使用提琴手或開發人員工具,以查看您是否偶然遇到404錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM