开发者

Uploadify won't work with my asp.net MVC 2 application

When I use uploadify to upload photos to the server I use the following script (The script is placed in the Photo.aspx (this is the view of the UploadController and the Photo action)):

    <script type="text/javascript">
    $(document).ready(function () {
        $("#fileInput").uploadify({
            uploader: "../../Images/uploadify.swf",
            script: "../../Upload/Upload.ashx",
            cancelImg: "../../Images/cancel.png",
            auto: true,
            multi: true,
            开发者_运维问答folder: "Folder/Photos",
            onError: function (a, b, c, d) {
                if (d.status == 404)
                    alert("Could not find upload script. Use a path relative to: bla ");
                else if (d.type === "HTTP")
                    alert("error " + d.type + ": " + d.info);
                else if (d.type === "File Size")
                    alert(c.name + " " + d.type + " Limit: " + Math.round(d.sizeLimit / 1024) + "KB");
                else
                    alert("error " + d.type + ": " + d.text);
            }
        });
    });  
</script>

Found here

Everything works fine until I've selected the files and the script starts uploading. Error HTTP: 404. This means, it doesn't find the script file. I tried everything: script: "../../Upload.ashx", script: "../Upload.ashx", script: "Upload.ashx", etc..

The Upload.ashx is placed in Views/Upload/Upload.ashx (This folder also contains the Photo.aspx from the UploadController which contains the uploadify script). The scripts are loaded at the end of my page. I don't understand why uploadify can't find the script when I use the 'script: "Upload.ashx"' property. Can someone help with this?


The reason why you are always getting a 404 is because you should never link directly to a view. Create an action method in a controller that accepts a HttpPostedFileBase file. Here's an article from Phil Haack: http://haacked.com/archive/2010/07/16/uploading-files-with-aspnetmvc.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜