在 ASP .NET MVC3 中实现的示例项目插件 jquery 文件上传插件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9361789/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sample project plugin jquery File Upload plugin implemented in ASP .NET MVC3
提问by rspaz16
I need to implement in my project ASP .NET MVC3 the jQuery file upload plugin:
我需要在我的项目 ASP .NET MVC3 中实现 jQuery 文件上传插件:
http://blueimp.github.com/jQuery-File-Upload/
http://blueimp.github.com/jQuery-File-Upload/
I have been Googling and I haven't found a whole project, only pieces of code. I don't know how to implement it.
我一直在谷歌搜索,我没有找到一个完整的项目,只有代码片段。我不知道如何实现它。
Can someone help me? Can someone tell me where I can download a sample project or code?
有人能帮我吗?有人可以告诉我在哪里可以下载示例项目或代码吗?
回答by Darin Dimitrov
Did you read the documentationof the plugin that you are trying to use? Did you try the basic plugin functionality? Did you try to create a new ASP.NET MVC 3 application in Visual Studio using the default template?
您是否阅读了您尝试使用的插件的文档?您是否尝试过基本的插件功能?您是否尝试使用默认模板在 Visual Studio 中创建新的 ASP.NET MVC 3 应用程序?
Did you try writing a simple controller:
您是否尝试编写一个简单的控制器:
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 }));
}
}
and a corresponding view:
和相应的视图:
<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"/>
If you haven't, I invite you to do so.
如果你还没有,我邀请你这样做。
回答by Maxim V. Pavlov
I've created a sample ASP.NET MVC 3 project on GitHubthat shows how to use a full plug-in functionality, including deletion and download.
我在 GitHub 上创建了一个示例 ASP.NET MVC 3 项目,展示了如何使用完整的插件功能,包括删除和下载。