如何在控制器上设置错误作为返回并在aspnet mvc 4中的uploadify上获取它?

时间:2013-01-30 22:39:17

标签: c# asp.net asp.net-mvc asp.net-mvc-4 uploadify

我没有想法。系统的构建方式我不确定我能做我必须做的事情。

这是处理来自uploadify的上传文件的控制器。

public ActionResult Upload(HttpPostedFileBase FileData, FormCollection form)
{
     try 
     {
        String path = String.Format("{0}{1}", caminhoArmazenamento, tipoDocNome);

        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
            FileData.SaveAs(path);
            //HERE I NEED SOME CONTROL TO RETURN THAT THINGS WENT RIGHT
        }
        else
        {
            FileData.SaveAs(path);
            //HERE I NEED SOME CONTROL TO RETURN THAT THINGS WENT RIGHT
        }
    }
    catch(exception)
    {
       //HERE I NEED SOME CONTROL SAYING THAT THINGS WENT WRONG
    }
}

这是uploadify:

$('#file_upload').uploadify({
        'swf': '../../Components/uploadify/uploadify.swf',
        'uploader': '/Operacao/Upload',
        'auto': false,
        'buttonImage': '../../Images/uploadify/importar.jpg',
        'buttonClass': 'uploadifyBtn',
        'width': '250',
        'height': '25',
        'onFallback': function () {
            alert('Versão do flash não compativel com o sistema de upload. Favor contactar o administrador do sistema!');
        },
        'onUploadError' : function(file, errorCode, errorMsg, errorString) {
            alert('O arquivo ' + file.name + ' não pode ser importado: ' + errorCode + ' - ' + errorMsg + ' - ' + errorString);
        },
        'onSelectError': function () {
            alert('Você não tem permissão para acessar o arquivo: "' + file.name + '" ou o arquivo está corrompido. Favor contactar o administrador do sistema.');
        }
    });

有没有人在asp net mvc 4中成功实现uploadfy? 无论我设置什么回报,我只得到一个或一般错误或成功的menagem。我需要更具体地实现错误控制,例如,如果无法创建目录或无法上载文件以及原因。感谢

1 个答案:

答案 0 :(得分:1)

据我所知,根据返回服务器代码,uploadify将执行不同的回调。

以下是服务器返回404以及uploadify响应的示例: http://www.uploadify.com/documentation/uploadify/onuploaderror/

您要做的是根据发生的情况返回相应的Response.StatusCode(200,404,501)。

How to get MVC action to return 404