我需要在我的ASP .NET MVC3项目中实现jQuery文件上传插件:
http://blueimp.github.com/jQuery-File-Upload/
我已经通过谷歌搜索,但只找到了一些代码片段而不是整个项目。我不知道该如何实施。
有人可以帮助我吗?有人可以告诉我在哪里下载示例项目或代码吗?
我需要在我的ASP .NET MVC3项目中实现jQuery文件上传插件:
http://blueimp.github.com/jQuery-File-Upload/
我已经通过谷歌搜索,但只找到了一些代码片段而不是整个项目。我不知道该如何实施。
有人可以帮助我吗?有人可以告诉我在哪里下载示例项目或代码吗?
您是否阅读了您尝试使用的插件的文档?是否尝试了基本插件功能?是否尝试使用Visual Studio创建一个新的默认模板的ASP.NET MVC 3应用程序?
您是否尝试编写一个简单的控制器:
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(IEnumerable<HttpPostedFileBase> files)
{
foreach (var file in files)
{
var filename = Path.Combine(Server.MapPath("~/App_Data"), file.FileName);
file.SaveAs(filename);
}
return Json(files.Select(x => new { name = x.FileName }));
}
}
还需要对应的视图:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="@Url.Content("~/Scripts/blueimp/js/vendor/jquery.ui.widget.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/blueimp/js/jquery.iframe-transport.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/blueimp/js/jquery.fileupload.js")" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#fileupload').fileupload({
dataType: 'json',
url: '@Url.Action("index")',
done: function (e, data) {
$.each(data.result, function (index, file) {
$('<p/>').text(file.name).appendTo(document.body);
});
}
});
});
</script>
<input id="fileupload" type="file" name="files" multiple="multiple"/>
如果您尚未这样做,我邀请您这样做。