使用Valums Ajax Uploader上传的ASP.NET MVC文件没有创建视图

时间:2012-06-29 13:08:42

标签: javascript ajax asp.net-mvc-3

我按照这个tutorial,将js,css和gif放在相应的文件夹中。问题是视图没有表现出来。

<link href="@Url.Content("~/css/fileuploader.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/js/fileuploader.js")" type="text/javascript"></script>
<div id="file-uploader">
    <noscript>
        <p>
            Please enable JavaScript to use file uploader.</p>
    </noscript>
</div>
<script type="text/javascript">
var uploader = new qq.FileUploader({
element: document.getElementById('file-uploader'),
action: '@Url.Action("upload")' // put here a path to your page to handle uploading
//,allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'] // user this if you want to upload only pictures
sizeLimit: 4000000, // max size, about 4MB
minSizeLimit: 0 // min size

 });
</script>

这个脚本有什么问题?

使用Firebug生成的错误是

missing } after property list

页面来源

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Home Page</title>
    <link href="/Content/Site.css" rel="stylesheet" type="text/css" />
    <script src="/Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
    <script src="/Scripts/modernizr-1.7.min.js" type="text/javascript"></script>
</head>
<body>
    <div class="page">
        <header>
            <div id="title">
                <h1>My MVC Application</h1>
            </div>
            <div id="logindisplay">
                    [ <a href="/Account/LogOn">Log On</a> ]

            </div>
            <nav>
                <ul id="menu">
                    <li><a href="/">Home</a></li>
                    <li><a href="/Home/About">About</a></li>
                </ul>
            </nav>
        </header>
        <section id="main">
            <link href="/css/fileuploader.css" rel="stylesheet" type="text/css" />
<script src="/js/fileuploader.js" type="text/javascript"></script>
<div id="file-uploader">
    <noscript>
        <p>
            Please enable JavaScript to use file uploader.</p>
    </noscript>
</div>
<script type="text/javascript">
var uploader = new qq.FileUploader({
element: document.getElementById('file-uploader'),
action: '/Home/upload' // put here a path to your page to handle uploading
//,allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'] // user this if you want to upload only pictures
sizeLimit: 4000000, // max size, about 4MB

minSizeLimit: 0 // min size

 });
</script>

        </section>
        <footer>
        </footer>
    </div>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

这里有一个尾随逗号,你应该删除:

minSizeLimit: 0, // min size

你在这里忘记了一个逗号:

action: '@Url.Action("upload")' // put here a path to your page to handle uploading

所以请努力编写有效的javascript:

<script type="text/javascript">
    var uploader = new qq.FileUploader({
        element: document.getElementById('file-uploader'),
        action: '@Url.Action("upload")',
        sizeLimit: 4000000,
        minSizeLimit: 0
    });
</script>

啊,我现在可以看到您复制粘贴的文章包含相同的错误。对不起,我以为这是你的错。请随时通知本文作者有关其代码中的错误。