首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在ASP .NET MVC3中实现的示例项目插件jquery文件上传插件

在ASP .NET MVC3中实现的示例项目插件jquery文件上传插件
EN

Stack Overflow用户
提问于 2012-02-20 21:17:43
回答 2查看 33.4K关注 0票数 15

我需要在我的项目中实现ASP .NET MVC3的jQuery文件上传插件:

http://blueimp.github.com/jQuery-File-Upload/

我一直在谷歌搜索,我还没有找到一个完整的项目,只有代码片段。我不知道如何实现它。

有人能帮我吗?有人能告诉我在哪里可以下载示例项目或代码吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-03-16 08:20:31

我已经创建了一个sample ASP.NET MVC 3 project on GitHub,它展示了如何使用完整的插件功能,包括删除和下载。

票数 28
EN

Stack Overflow用户

发布于 2012-02-20 22:26:22

你是否阅读了你正在尝试使用的插件的documentation?你试过basic plugin functionality了吗?您是否尝试使用默认模板在Visual Studio中创建新的ASP.NET MVC3应用程序?

你有没有试过写一个简单的控制器:

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"/>

如果您还没有,我邀请您这样做。

票数 46
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9361789

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档