2

我尝试在我的 MVC4 项目中实现Fineuploader,但它总是无法上传。我做了什么:

将 css 和 js 文件添加到我的视图中:

<link href="~/Content/fineuploader.css" rel="stylesheet" />
<script src="~/Scripts/js/util.js"></script>
<script src="~/Scripts/js/button.js"></script>
<script src="~/Scripts/js/dnd.js"></script>
<script src="~/Scripts/js/handler.base.js"></script>
<script src="~/Scripts/js/handler.form.js"></script>
<script src="~/Scripts/js/handler.xhr.js"></script>
<script src="~/Scripts/js/header.js"></script>
<script src="~/Scripts/js/jquery-plugin.js"></script> 
<script src="~/Scripts/js/uploader.basic.js"></script>
<script src="~/Scripts/js/uploader.js"></script> 

添加了上传按钮的代码和脚本的执行(我认为这不对?)

<script>
    function createUploader() {
        var uploader = new qq.FineUploader({
            element: document.getElementById('fine-uploader'),
            debug: true,
            request: {
                endpoint: '/Upload/UploadFile/'
            }
        });
    }

    window.onload = createUploader;
</script>

将 C# 文件添加到我的项目FineUpload.csFineUploadResult.csControllerUploadController.cs中。我还向控制器添加了一条路由:

routes.MapRoute(
                    name: "upload",
                    url: "Upload/UploadFile",
                    defaults: new { controller = "Upload", action = "UploadFile" }
                );

控制器是:

public class UploadController : Controller
{
    [HttpPost]
    public FineUploaderResult UploadFile(FineUpload upload, string extraParam1, int extraParam2)
    {
      ...
    }
}

但从UploadFile不在服务器上调用。

4

1 回答 1

4

您似乎弄乱了您的脚本内容(顺序和所有内容)。您应该选择是否需要使用 FineUploaderBasic 模式、FineUploader 模式或 jQuery 插件模式。鉴于您的代码,您似乎正在使用标准模式。

这是一个完整的工作示例和最小的标记:

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <title>Index</title>
    <link href="~/Content/fineuploader.css" rel="stylesheet" />
</head>
<body>
    <div id="fine-uploader">Click me to upload a file</div>

    <script src="~/Scripts/js/header.js"></script>
    <script src="~/Scripts/js/util.js"></script>
    <script src="~/Scripts/js/button.js"></script>
    <script src="~/Scripts/js/handler.base.js"></script>
    <script src="~/Scripts/js/handler.form.js"></script>
    <script src="~/Scripts/js/handler.xhr.js"></script>
    <script src="~/Scripts/js/uploader.basic.js"></script>
    <script src="~/Scripts/js/dnd.js"></script>
    <script src="~/Scripts/js/uploader.js"></script> 
    <script type="text/javascript">
        function createUploader() {
            var uploader = new qq.FineUploader({
                element: document.getElementById('fine-uploader'),
                debug: true,
                request: {
                    endpoint: '@Url.Action("UploadFile", "Uploader")'
                }
            });
        }
        createUploader();
    </script>
</body>
</html>

此外,您的控制器操作似乎采用了一些额外的整数参数。如果你没有在请求中指定它,这个请求显然会失败。在这种情况下使用可为空的整数。

于 2013-02-19T10:08:40.410 回答