Asp.net mvc 3 mvc3&;Uploadify-如何显示自定义错误消息?

Asp.net mvc 3 mvc3&;Uploadify-如何显示自定义错误消息?,asp.net-mvc-3,uploadify,Asp.net Mvc 3,Uploadify,上传文件后,在将其保存到磁盘之前,我正在进行一些验证 如果出现故障,我想向用户显示自定义错误消息。 我在这里发现了一些奇怪的东西 如何在MVC3中做到这一点 托尼 直接取自我目前正在开发的ab mvc3应用程序: <script type="text/javascript"> function initupLoadify() { $("#fileInput").uploadify({ uploader: '@Url.Content("~

上传文件后,在将其保存到磁盘之前,我正在进行一些验证

如果出现故障,我想向用户显示自定义错误消息。 我在这里发现了一些奇怪的东西

如何在MVC3中做到这一点

托尼

直接取自我目前正在开发的ab mvc3应用程序:

<script type="text/javascript">
    function initupLoadify() {
        $("#fileInput").uploadify({
            uploader: '@Url.Content("~/scripts/swf/uploadify.swf")',
            script: '@Url.Action("Upload", "Home")',
            cancelImg: '@Url.Content("~/Content/cancel.png")',
            auto: true,
            sizeLimit: 5500000,
            fileDataName: 'fileData',
            //scriptData: { 'propertyId': $("#PropertyID").val() },
            buttonText: 'Add Schedule',
            wmode: 'transparent',
            //buttonImg: '@Url.Content("~/Content/button.png")', // make nice gradient image for button
            onComplete: function (event, queueId, fileObj, response) {
                $("#msg").html(response);
                // do something
                setTimeout(2000, window.location = '@Url.Action("Index")' + '?id=' + response);
                return true;
            },
            onCancel: function (evt, queueId, fileObj, data) {
                $("#msg").html("<br />Operation cancelled");
                return true;
            },
            onOpen: function (evt, queueId, fileObj) {
                $("#msg").html("<br />Upload in progress");
                return true;
            },
            onError: function (event, queueId, fileObj, errorObj) {
                $("#msg").html(fileObj.name + " was not uploaded ");
                if (errorObj.status == 404)
                    $("#msg").html("Could not find upload script. Use a path relative to: " + "<?= getcwd() ?>");
                else if (errorObj.type === "HTTP")
                    $("#msg").html("error " + errorObj.type + ": " + errorObj.status);
                else if (errorObj.type === "File Size")
                    $("#msg").html(fileObj.name + " " + errorObj.type + " Limit: " + errorObj.info / 1000 + " KB");
                else
                    $("#msg").html("error " + errorObj.type + ": " + errorObj.text);
            }
        });
    };
</script>

函数initupLoadify(){
$(“#文件输入”)。上载({
上传程序:'@Url.Content(“~/scripts/swf/uploadify.swf”),
脚本:'@Url.Action(“上传”、“主页”),
cancelImg:“@Url.Content(“~/Content/cancel.png”)”,
是的,
sizeLimit:5500000,
fileDataName:'fileData',
//scriptData:{'propertyId':$(“#propertyId”).val(),
buttonText:“添加计划”,
wmode:'透明',
//buttonImg:“@Url.Content(“~/Content/button.png”),//为按钮制作漂亮的渐变图像
onComplete:函数(事件、队列ID、fileObj、响应){
$(“#msg”).html(回复);
//做点什么
setTimeout(2000,window.location='@Url.Action(“Index”)'+'?id='+response);
返回true;
},
onCancel:函数(evt、queueId、fileObj、data){
$(“#msg”).html(“
操作已取消”); 返回true; }, onOpen:函数(evt、queueId、fileObj){ $(“#msg”).html(“
正在上载”); 返回true; }, onError:函数(事件、队列ID、fileObj、errorObj){ $(“#msg”).html(fileObj.name+“未上载”); 如果(errorObj.status==404) $(“#msg”).html(“找不到上载脚本。请使用相对于“+”)的路径; else if(errorObj.type==“HTTP”) $(“#msg”).html(“error”+errorObj.type+”:“+errorObj.status”); else if(errorObj.type==“文件大小”) $(“#msg”).html(fileObj.name+”“+errorObj.type+”限制:“+errorObj.info/1000+”KB”); 其他的 $(“#msg”).html(“error”+errorObj.type+”:“+errorObj.text); } }); };
希望这有帮助

这是一个MVC 3


如果您使用的是3.0+版本,请使用而不是onComplete(认识到它们的参数不同)。

我见过类似的代码,但它只显示文件的数据。但是,如果我想显示“服务器上到底发生了什么”的消息,该怎么办?tony-我明白你的意思(控制器/服务层代码,虽然从问题中没有意识到这一点)。我还没有时间来处理这个问题,但你现在已经开始我的“研究”了,所以我会有一个数字。我想是时候把这个插件改成其他插件了。我正在使用uploadify 3.1.1,而且我没有可用的
onComplete
方法。
onUploadComplete
方法传递的参数与此处概述的参数不同。你在这个版本的uploadify上工作了吗?嗨,webnet,不幸的是,我没有使用3.1.1版本。让我知道你过得怎么样。