2012-05-18 78 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錯誤。