Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Telerik asp.net MVC文件上载控件_C#_Asp.net Mvc_Telerik_Telerik Mvc - Fatal编程技术网

C# Telerik asp.net MVC文件上载控件

C# Telerik asp.net MVC文件上载控件,c#,asp.net-mvc,telerik,telerik-mvc,C#,Asp.net Mvc,Telerik,Telerik Mvc,我在Razor视图(目录/产品视图)中使用Telerik asp.net MVC 3文件控件,如下所示: @(Html.Telerik().Upload() .Name("orderImageAtachment") .Async(async => async.Save("Save", "Catalog").AutoUpload(true)) .ClientEvents(events => events .OnSuccess("ItemImage

我在Razor视图(
目录
/
产品
视图)中使用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")
    )
)
 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();
    }
我创建了一个
ActionResult
,如下所示:

@(Html.Telerik().Upload()
    .Name("orderImageAtachment")
    .Async(async => async.Save("Save", "Catalog").AutoUpload(true))
    .ClientEvents(events => events
        .OnSuccess("ItemImageOnSuccess")
        .OnError("ItemImageOnError")
    )
)
 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
参数(至少看起来它在代码段中没有使用)

我会尝试在你使用的浏览器中使用fiddler或开发者工具,看看你是否偶然遇到404错误