0

我在我的 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 中添加一些东西吗?请建议。

4

1 回答 1

0

我有点困惑,此时它不起作用,但我假设它没有击中你的控制器中的动作。我会确保你正在尝试一个相当小的文件,默认限制是 4mb。

Save此外,您的Action签名看起来与您在上传的async.Save(...). 我不确定它是否重要,因为它是一个字符串,但您可以尝试删除 Save 操作的CompID参数(至少看起来不像它在片段中使用的那样)。

我会尝试在您使用的任何浏览器中使用提琴手或开发人员工具来查看您是否偶然遇到 404 错误。

于 2012-06-26T20:19:07.723 回答