2012-05-18 76 views
0

我使用Telerik的asp.net MVC 3文件控制在我的Razor视图(Catalog/Product查看)是这样的:Telerik的asp.net MVC FileUpload控件

@(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中添加一些内容吗?请建议。

回答

0

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

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

我想尝试使用无论您使用的浏览器中的提琴手或开发人员工具,看看你是否偶然得到404错误。