asp.net mvc ajax upload solution?

让人想犯罪 __ 提交于 2019-12-02 21:16:50

Personally I like Valums Ajax Upload.


UPDATE:

As requested in the comments section here's an example of how this could be used with ASP.NET MVC.

Controller:

public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View();
    }

    [HttpPost]
    public ActionResult Upload(string qqFile)
    {
        // The upload action will be called by the client control
        // for each file that was selected by the user for upload

        var path = Server.MapPath("~/App_Data");
        var file = Path.Combine(path, qqFile);
        using (var output = System.IO.File.Create(file))
        {
            Request.InputStream.CopyTo(output);
        }
        return Json(new { success = true });
    }
}

View (~/Views/Home/Index.cshtml):

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Ajax Upload demo with ASP.NET MVC</title>
    <link href="@Url.Content("~/Content/fileuploader.css")" rel="stylesheet" type="text/css" />
</head>
<body>
    <div id="file-uploader">       
        <noscript>          
            <p>Please enable JavaScript to use file uploader.</p>
            <!-- or put a simple form for upload here -->
        </noscript>         
    </div>

    <script src="@Url.Content("~/Scripts/fileuploader.js")" type="text/javascript"></script>
    <script type="text/javascript">
        var uploader = new qq.FileUploader({
            element: document.getElementById('file-uploader'),
            action: '@Url.Action("Upload", "Home")'
        });    
    </script>
</body>
</html>

Try Uploadify or PLupload, these two can be customized for different languages and runtime

Another "personally I like": Telerik Upload. We are using it in our current product. It's designed specifically for ASP.NET MVC.

Mohamed Arabi

This answer is great but you should consider check this post for IE problems, And check @Shane Km answer.

here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!