2012-08-12 74 views
0

我正在使用Uploadify版本3.1。當我嘗試上傳文件時,出現IO錯誤。Uploadify with MVC4 does not working。 IO錯誤

當我保持調試器在行動方法,它沒有擊中。

我試過以下的鏈接,但即使認爲同樣的錯誤。

Getting HTTP Error while using uploadify on Asp.net MVC application

請給我建議。

查看

@{ 
    Layout = null; 
} 
<!DOCTYPE html> 
<html> 
<head> 
    <meta charset="utf-8" /> 
    <link href="@Url.Content("~/uploadify/uploadify.css")" rel="stylesheet" type="text/css" /> 
</head> 
<body> 
    <div id="file_upload"></div> 

    <script src="@Url.Content("~/Scripts/jquery-1.6.2.js")" type="text/javascript"></script> 
@* <script src="@Url.Content("~/uploadify/swfobject.js")" type="text/javascript"></script>*@ 
    <script src="@Url.Content("~/uploadify/jquery.uploadify-3.1.js")" type="text/javascript"></script> 
    <script type="text/javascript"> 
     $('#file_upload').uploadify({ 
      'uploader': '@Url.Content("~/uploadify/uploadify.swf")', 
      'flash_url': '@Url.Content("~/uploadify/uploadify.swf")', 
      'fileObjName': 'fileData', 
      'script': '@Url.Action("Upload", "Home")', 
      'cancelImg': '@Url.Content("~/uploadify/cancel.png")', 
      'folder': '@Url.Content("~/content/images")', 
      'fileDesc': 'Image Files', 
      'fileExt': '*.jpg;*.jpeg;*.gif;*.png', 
      'auto': true 
     });  
    </script> 
</body> 
</html> 

[控制器]

public class HomeController : Controller 
{ 
    public ActionResult Index() 
    { 
     ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application."; 

     return View(); 
    } 
} 


[HttpPost] 
public ActionResult Upload(HttpPostedFileBase fileData) 
{ 
    if (fileData != null && fileData.ContentLength > 0) 
    { 
     var fileName = Server.MapPath("~/Content/Images/" + Path.GetFileName(fileData.FileName)); 
     fileData.SaveAs(fileName); 
     return Json(true); 
    } 
    return Json(false); 
} 

回答

0

嘗試這樣的:

 $('#file_upload').uploadify({ 
      'checkExisting': 'Content/uploadify/check-exists.php', 
      'swf': '@Url.Content("~/uploadify/uploadify.swf")', 
      'uploader': '@Url.Action("Upload", "Home")', 
      'auto': false, 
      'buttonText': 'Browse', 
      'fileTypeExts': '*.jpg;*.jpeg;*.png;*.gif', 
      'removeCompleted': false 
     }); 

希望這有助於。

0

您是否檢查了上傳文件的文件夾的文件夾權限?您需要將該文件夾的權限設置爲IIS用戶和網絡用戶以及

0

檢查您的控制器,操作必須是AllowAnonymous