Backload和jquery File Uploader - 不要正确显示上传的文件

时间:2013-09-18 01:16:22

标签: jquery asp.net-mvc json file-upload

我正在使用带有jquery客户端脚本的MVC 4和Backload文件上传器。我使用nuget获取Demo包,下载控制器和视图作为起点。

我的问题出现在我的本地服务器和我的在线服务器上,在我上传文件后,应用程序无法准确显示上传的所有文件。通常它只会显示4或5个文件并忽略其余文件。即使我删除了正在显示的文件之一并刷新页面,它仍然显示相同的4或5个图像。我已经确认应用程序正在上载和/或删除文件。我尝试通过点击cntl F5清除缓存,但无济于事。

任何人都可以指出我正确的方向来纠正这个问题。以下是来自NuGet下载的演示的视图和控制器。

控制器:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Spotless_Interiors.Controllers
{
    [Authorize]
    public class BackloadDemoController : Controller
    {

        public ActionResult Index()
        {

            return View();
        }


    }
}

查看:

@{
    ViewBag.Title = "File Upload";

}

@section topScripts {
    @Styles.Render("~/Content/themes/base/css")
    @Styles.Render("~/Content/css")

    <!-- We use Backloads. bundeling feature to register only those client side javascript and style files of the jQuery File Upload Plugin
         that are needed  -->
    @Styles.Render("~/bundles/fileupload/bootstrap/BasicPlusUI/css")

     <!-- Bootstrap CSS fixes for IE6 -->
    <!--[if lt IE 7]><link rel="stylesheet" href="/Content/FileUpload/css/bootstrap/bootstrap-ie6.debug.css"><![endif]-->

    <!--[if lt IE 9]><script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
    <!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><![endif]-->
}

@section scripts {
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/jqueryui")

    <!-- We use Backloads. bundeling feature to register only those client side javascript and style files of the jQuery File Upload Plugin that are needed  -->
    @Scripts.Render("~/bundles/fileupload/bootstrap/BasicPlusUI/js")

    <!-- Initialize the jQuery File Upload Plugin -->
    <script src="~/Scripts/FileUpload/backload.demo.js"></script>

}


 <div>
        <!-- The file upload form used as target for the file upload widget -->
        <form id="fileupload" action="/Backload/UploadHandler" method="POST" enctype="multipart/form-data">
            <!-- Redirect browsers with JavaScript disabled to the origin page -->
            <noscript><input type="hidden" name="redirect" value="/"></noscript>
            <!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
            <div class="row fileupload-buttonbar">
                <div class="span7">
                    <!-- The fileinput-button span is used to style the file input field as button -->
                    <span class="btn btn-success fileinput-button">
                        <i class="icon-plus icon-white"></i>
                        <span>Add files...</span>
                        <input type="file" name="files[]" multiple>
                    </span>
                    <button type="submit" class="btn btn-primary start">
                        <i class="icon-upload icon-white"></i>
                        <span>Start upload</span>
                    </button>
                    <button type="reset" class="btn btn-warning cancel">
                        <i class="icon-ban-circle icon-white"></i>
                        <span>Cancel upload</span>
                    </button>
                    <button type="button" class="btn btn-danger delete">
                        <i class="icon-trash icon-white"></i>
                        <span>Delete</span>
                    </button>
                    <input type="checkbox" class="toggle">
                    <!-- The loading indicator is shown during file processing -->
                    <span class="fileupload-loading"></span>
                </div>
                <!-- The global progress information -->
                <div class="span5 fileupload-progress fade">
                    <!-- The global progress bar -->
                    <div class="progress progress-success progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100">
                        <div class="bar" style="width:0%;"></div>
                    </div>
                    <!-- The extended global progress information -->
                    <div class="progress-extended">&nbsp;</div>
                </div>
            </div>
            <!-- The table listing the files available for upload/download -->
            <table role="presentation" class="table table-striped"><tbody class="files" data-toggle="modal-gallery" data-target="#modal-gallery"></tbody></table>
        </form>  

        <!-- The template to display files available for upload -->
        <script id="template-upload" type="text/x-tmpl">
        {% for (var i=0, file; file=o.files[i]; i++) { %}
            <tr class="template-upload fade">
                <td>
                    <span class="preview"></span>
                </td>
                <td>
                    <p class="name">{%=file.name%}</p>
                    {% if (file.error) { %}
                        <div><span class="label label-important">Error</span> {%=file.error%}</div>
                    {% } %}
                </td>
                <td>
                    <p class="size">{%=o.formatFileSize(file.size)%}</p>
                    {% if (!o.files.error) { %}
                        <div class="progress progress-success progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="bar" style="width:0%;"></div></div>
                    {% } %}
                </td>
                <td>
                    {% if (!o.files.error && !i && !o.options.autoUpload) { %}
                        <button class="btn btn-primary start">
                            <i class="icon-upload icon-white"></i>
                            <span>Start</span>
                        </button>
                    {% } %}
                    {% if (!i) { %}
                        <button class="btn btn-warning cancel">
                            <i class="icon-ban-circle icon-white"></i>
                            <span>Cancel</span>
                        </button>
                    {% } %}
                </td>
            </tr>
        {% } %}
        </script>
        <!-- The template to display files available for download -->
        <script id="template-download" type="text/x-tmpl">
        {% for (var i=0, file; file=o.files[i]; i++) { %}
            <tr class="template-download fade">
                <td>
                    <span class="preview">
                        {% if (file.thumbnail_url) { %}
                            <a href="{%=file.url%}" title="{%=file.name%}" data-gallery="gallery" download="{%=file.name%}"><img src="{%=file.thumbnail_url%}"></a>
                        {% } %}
                    </span>
                </td>
                <td>
                    <p class="name">
                        <a href="{%=file.url%}" title="{%=file.name%}" data-gallery="{%=file.thumbnail_url&&'gallery'%}" download="{%=file.name%}">{%=file.name%}</a>
                    </p>
                    {% if (file.error) { %}
                        <div><span class="label label-important">Error</span> {%=file.error%}</div>
                    {% } %}
                </td>
                <td>
                    <span class="size">{%=o.formatFileSize(file.size)%}</span>
                </td>
                <td>
                    <button class="btn btn-danger delete" data-type="{%=file.delete_type%}" data-url="{%=file.delete_url%}"{% if (file.delete_with_credentials) { %} data-xhr-fields='{"withCredentials":true}'{% } %}>
                        <i class="icon-trash icon-white"></i>
                        <span>Delete</span>
                    </button>
                    <input type="checkbox" name="delete" value="1" class="toggle">
                </td>
            </tr>
        {% } %}
        </script>      
    </div>

1 个答案:

答案 0 :(得分:1)

由于所有文件都已正确上传/删除并且您清除了客户端缓存,因此这似乎是服务器端缓存问题。您应该使用Fiddler来检查请求和响应的chache标头。

您是否在配置文件中设置了任何缓存选项?尝试在配置文件中设置这样的内容: <cacheManager lastModified="false" etag="false" expires="0" location="None" mustRevalidate="true" />。请注意,据我所知,cacheManager是Pro功能,它在本地工作,但不能在具有Standard许可证的远程服务器上运行(我的公司拥有带源代码的Enterprise许可证)

但正如我上面所说,我认为它与您的服务器端缓存设置更相关。因此,上传一个文件,然后删除文件并使用Fiddler检查所有请求/响应。来自Backload的Json共振应始终反映当前文件状态,即使返回304也是如此。禁用Web.config中的所有服务器端缓存设置。