很难说的问题可能与你的代码是什么。你将不得不调试它。
这里是一个完整的工作示例:
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);
}
}
视图(~/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>
确保~/Content/Images
文件夹,你是哪个服务器上存在上传或控制器中的操作将抛出一个例外。您还会注意到,在我的示例中,所有url都是通过url助手引用的,而不是对它们进行硬编码。通过这种方式,应用程序无论是托管在IIS中的虚拟目录还是本地托管都可以保证工作。
我已经使用了uploadify 2.1.4版,我下载并把内容在服务器上的文件夹~/uploadify
。
,你应该知道的另一件事是,可以发布到ASP.NET可能在web.config中使用httpRuntime
element配置文件的限制。所以,如果你nitend上传大文件请确保您已经调整了maxRequestLength
和executionTimeout
设置到所需的最大值,要允许:
<system.web>
<httpRuntime maxRequestLength="102400" executionTimeout="3600" />
</system.web>
我想你的代码,但没有露面....可能是你忘了写输入元素.....会在一段时间 –
@Pankaj Upadhyay添加它们,让你有在我的代码没有输入元素。只有它使用的Uploadify插件,并转化成一个按钮,让你选择文件,并将其上传到服务器的单个''
。如果你在运行这个例子时遇到麻烦,你可以把你的代码发给我,这样我就可以看看它有什么问题了。 –我创建了一个新的项目,并试图您的代码....它的工作原理实际上.....在我的项目我是在插入一些其他性质的HTTP形式file_upload DIV .....会考虑,看看什么错误.....感谢队友 –