It's hard to say what the problem might be with your code. You will have to debug it.
Here's a full working example:
public class HomeController : Controller
{
public ActionResult Index()
{
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);
}
}
View (~/Views/Home/Index.cshtml):
@{
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.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/uploadify/swfobject.js")" type="text/javascript"></script>
<script src="@Url.Content("~/uploadify/jquery.uploadify.v2.1.4.js")" type="text/javascript"></script>
<script type="text/javascript">
$('#file_upload').uploadify({
'uploader': '@Url.Content("~/uploadify/uploadify.swf")',
'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>
Make sure that the ~/Content/Images folder to which you are uploading exists on your server or the controller action will throw an exception. You will also notice how in my example all urls are referenced through url helpers instead of hardcoding them. This way the application is guaranteed to work no matter whether it is hosted inside a virtual directory in IIS or locally.
I have used the uploadify version 2.1.4 that I downloaded and put the contents in the ~/uploadify folder on the server.
Another thing that you should be aware of is the limit of files that can be posted to ASP.NET which could be configured in web.config using the httpRuntime element. So if you nitend to upload large files make sure you have adjusted the maxRequestLength and executionTimeout settings to the desired maximum values you want to allow:
<system.web>
<httpRuntime maxRequestLength="102400" executionTimeout="3600" />
</system.web>