Asp.net mvc 指定目录时出现plupload错误

Asp.net mvc 指定目录时出现plupload错误,asp.net-mvc,plupload,Asp.net Mvc,Plupload,我已经在我的MVC应用程序中实现了plupload。一切进展顺利,但仍在眼前 我决定将其移到自己的文件中: 它不再工作,因为找不到plupload.flash.swf或plupload.silverlight.xap 以下是pluploadimplementation.js的内容: $(function () { $("#dialog").dialog({ autoOpen: false, buttons: { "OK": fu

我已经在我的MVC应用程序中实现了plupload。一切进展顺利,但仍在眼前

我决定将其移到自己的文件中:

它不再工作,因为找不到plupload.flash.swf或plupload.silverlight.xap

以下是pluploadimplementation.js的内容:

$(function () {
    $("#dialog").dialog({

        autoOpen: false,
        buttons: {
            "OK": function () {
                var invoiceComment = {
                    InvoiceId: invoiceId,
                    Comment: $('#comment').val()
                };
                $.post('/Invoice/AddComment', invoiceComment);
                $(this).dialog('close');
            }
        }
    });
    $(".btncomment").click(function () {
        invoiceId = $(this).attr("data-invoiceid");
        $("#dialog").dialog('open');
    });

    var filelist = $('#filelist');
    var pickfiles = $('#pickfiles');
    var uploadfiles = $('#uploadfiles');

    var uploader = new plupload.Uploader({
        runtimes: 'flash,silverlight,html5,html4',
        //runtimes: 'silverlight,html5, html4',
        //runtimes: 'html5,html4',
        //runtimes: 'html4',
        browse_button: pickfiles.attr('id'),
        container: 'container',
        max_file_size: '10mb',
        //chunk_size: '1mb',
        multi_selection: false,
        multipart: true,
        urlstream_upload: true,
        url: '@Url.Action("Upload", "Invoice")',
        flash_swf_url: '@Url.Content("~/Scripts/plupload/js/plupload.flash.swf")',
        silverlight_xap_url: '@Url.Content("~/Scripts/plupload/js/plupload.silverlight.xap")',
        filters: [
            { title: "Image Files", extensions: "jpg,gif,png,pdf" },
            { title: "Zip Files", extensions: "zip" },
            { title: "Office Files", extensions: "doc,docx,xls,xlsx" }
            ],
        resize: { width: 320, height: 240, quality: 90 }
    });

    uploader.bind('Init', function (up, params) {
        showpickfiles(true);
    });

    uploadfiles.click(function (e) {
        uploader.start();
        e.preventDefault();
    });

    uploader.init();

    uploader.bind('FilesAdded', function (up, files) {
        filelist.empty();

        $.each(files, function (i, file) {
            filelist.append('<div id="' + file.id + '">' + file.name +
                ' (' + plupload.formatSize(file.size) + ') <b></b>' +
                '<a href="#" id="cancel' + file.id + '" class="cancel"> [Cancel]</a>');

            //Bind cancel click event
            $('#cancel' + file.id).click(function () {
                $('#' + file.id).remove();
                showpickfiles(true);
                uploader.removeFile(file);
                uploader.refresh();
            });

            showpickfiles(false);
        });

        up.refresh(); // Reposition Flash/Silverlight
    })

    uploader.bind('UploadProgress', function (up, file) {
        $('#' + file.id + " b").html(file.percent + "%");
    });

    uploader.bind('Error', function (up, err) {
        if (err.code == -600) {
            filelist.append('<div style="color: #CC0000;">Error - File size is greater than 10MB'
            + (err.file ? ', File: ' + err.file.name : "") + '</div>');
        }
        else {
            filelist.append('<div style="color: #CC0000;">Error - ' + err.message
                + (err.file ? ', File: ' + err.file.name : "") + '</div>');
        }

        up.refresh(); // Reposition Flash/Silverlight
    });

    uploader.bind('FileUploaded', function (up, file) {
        $('#' + file.id + " b").html("100%");
        $('#cancel' + file.id).remove();
        pickfiles.html('[Replace Invoice]');
        showpickfiles(true);
        up.refresh();
    });

    var showpickfiles = function (show) {
        if (show) {
            pickfiles.show();
            uploadfiles.hide();
        } else {
            pickfiles.hide();
            uploadfiles.show();
        }
    }
});
$(函数(){
$(“#对话框”)。对话框({
自动打开:错误,
按钮:{
“OK”:函数(){
var invoiceComment={
InvoiceId:InvoiceId,
注释:$(“#注释”).val()
};
$.post('/Invoice/AddComment',invoiceComment);
$(this.dialog('close');
}
}
});
$(“.btncomment”)。单击(函数(){
invoiceId=$(this.attr(“数据invoiceId”);
$(“#dialog”).dialog('open');
});
var filelist=$(“#filelist”);
var pickfiles=$(“#pickfiles”);
var uploadfiles=$(“#uploadfiles”);
var uploader=新的plupload.uploader({
运行时:“flash、silverlight、html5、html4”,
//运行时:“silverlight、html5、html4”,
//运行时:“html5,html4”,
//运行时:“html4”,
浏览按钮:pickfiles.attr('id'),
容器:'容器',
最大文件大小:“10mb”,
//块大小:“1mb”,
多重选择:错误,
多部分:正确,
urlstream_上传:true,
url:'@url.Action(“上传”、“发票”),
flash_swf_url:“@url.Content(~/Scripts/plupload/js/plupload.flash.swf”),
silverlight_xap_url:“@url.Content(~/Scripts/plupload/js/plupload.silverlight.xap”),
过滤器:[
{标题:“图像文件”,扩展名:“jpg、gif、png、pdf”},
{标题:“Zip文件”,扩展名:“Zip”},
{标题:“办公文件”,扩展名:“doc、docx、xls、xlsx”}
],
调整大小:{宽度:320,高度:240,质量:90}
});
uploader.bind('Init',函数(up,params){
showpickfiles(true);
});
上载文件。单击(函数(e){
uploader.start();
e、 预防默认值();
});
uploader.init();
uploader.bind('FilesAdded',函数(up,files){
filelist.empty();
$.each(文件、函数(i、文件){
filelist.append(“”+file.name+
“(“+plupload.formatSize(file.size)+”)”+
'');
//绑定取消单击事件
$(“#取消”+file.id)。单击(函数(){
$('#'+file.id).remove();
showpickfiles(true);
uploader.removeFile(文件);
uploader.refresh();
});
showpickfiles(假);
});
up.refresh();//重新定位Flash/Silverlight
})
uploader.bind('UploadProgress',函数(up,file){
$('#'+file.id+“b”).html(file.percent+“%”);
});
uploader.bind('Error',函数(up,err){
如果(错误代码==-600){
filelist.append('错误-文件大小大于10MB'
+(err.file?',file:'+err.file.name:)+'';
}
否则{
filelist.append('Error-'+err.message
+(err.file?',file:'+err.file.name:)+'';
}
up.refresh();//重新定位Flash/Silverlight
});
uploader.bind('fileupload',函数(up,file){
$('#'+file.id+“b”).html(“100%”);
$('#取消'+file.id).remove();
html(“[Replace Invoice]”);
showpickfiles(true);
up.refresh();
});
var showpickfiles=函数(显示){
如果(显示){
pickfiles.show();
hide();
}否则{
pickfiles.hide();
uploadfiles.show();
}
}
});
我是否错误地指定了这些文件的位置

我是否错误地指定了这些文件的位置

是的,你有。您已经在静态javascript文件中使用了
@Url.Content
服务器端帮助程序。只能在视图内部使用服务器端构件

有两种可能性:

  • 在一些视图中移动包含内联
    声明中的所有设置和路径的
    上传器
    javascript变量,以便url帮助程序工作
  • #uploadfiles
    DOM元素上使用HTML5 data-*属性:

    <div id="uploadfiles" data-swfurl="@Url.Content("~/Scripts/plupload/js/plupload.flash.swf")" data-xapurl="@Url.Content("~/Scripts/plupload/js/plupload.silverlight.xap")">Upload</div>
    
var uploadfiles = $('#uploadfiles');

var uploader = new plupload.Uploader({
    runtimes: 'flash,silverlight,html5,html4',
    //runtimes: 'silverlight,html5, html4',
    //runtimes: 'html5,html4',
    //runtimes: 'html4',
    browse_button: pickfiles.attr('id'),
    container: 'container',
    max_file_size: '10mb',
    //chunk_size: '1mb',
    multi_selection: false,
    multipart: true,
    urlstream_upload: true,
    url: '@Url.Action("Upload", "Invoice")',
    flash_swf_url: uploadfiles.data('swfurl'),
    silverlight_xap_url: uploadfiles.data('xapurl'),
    filters: [
        { title: "Image Files", extensions: "jpg,gif,png,pdf" },
        { title: "Zip Files", extensions: "zip" },
        { title: "Office Files", extensions: "doc,docx,xls,xlsx" }
        ],
    resize: { width: 320, height: 240, quality: 90 }
});