2012-08-12 77 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