在Internet Explorer中提交文件内容时出现问题

时间:2010-09-28 18:24:03

标签: jquery asp.net-mvc jform

我通过jquery使用Jform.js插件提交我的文件,并且它在Firefox中工作但是当我在IE8文件上尝试正确地进行报道但是文件上传控制被隐藏,当我评论IE条件时,文件上传控件不会更多得到隐藏但是当我在我的控制器中检查Request.Files [0] .ContentLength时它有0值。这是我的代码,可能是我做错了什么?我使用Asp.net MVC和jquery-1.4.2

        var myform = document.createElement("form");    
        myform.style.display = "none"
        myform.action = "/Media/AjaxSubmit";
        myform.enctype = "multipart/form-data";
        myform.method = "post";
        var imageLoad;
        var imageLoadParent;
        if (document.all) {//IE
            imageLoad = document.getElementById(fileId);
            imageLoadParent = document.getElementById(fileId).parentNode;
            myform.appendChild(imageLoad);
            document.body.appendChild(myform);
        }
        else {//FF          
                imageLoad = document.getElementById(fileId).cloneNode(true);
                myform.appendChild(imageLoad);
                document.body.appendChild(myform);          
        }    
        $(myform).ajaxSubmit({ success: function (responseText) {    
});

2 个答案:

答案 0 :(得分:2)

.ajaxSubmit之前的谵妄是什么?它看起来像90年代末的代码。我建议你只使用jQuery而不用担心跨浏览器问题:

$('form')
    .attr('action', '/Media/AjaxSubmit')
    .attr('method', 'post')
    .attr('enctype', 'multipart/form-data')
    .hide()
    .append($('#' + fileId).clone())
    .ajaxSubmit({
        success: function(responseText) {
            // ...
        }
    })
    .appendTo('body');

备注:硬编码的表单操作看起来很难看。您应该考虑使用HTML帮助程序来生成网址。

答案 1 :(得分:0)

解决方案很简单我只需在从ajaxsubmit函数响应时添加该浏览控件,代码如下

            $(myform).ajaxSubmit({ success: function (responseText) {
            if (document.all) {//IE
                imageLoadParent.appendChild(myform.firstChild);
            }
            else//FF                     
            {
                document.body.removeChild(myform);
            }