电子邮件附件无法在Chrome中使用

时间:2013-06-19 15:33:50

标签: c# jquery asp.net asp.net-mvc-3

我已成功将附件文件传递给我的控制器,但我遇到Chrome问题,不仅样式化了我的浏览...按钮并附加了“没有文件选择”等文本,而且UploadAttachment_Complete函数也没有返回显示的文件名和因此用户不知道文件已上传。我想我需要在这里问一个问题。为什么Chrome会破坏我的代码?如果没有......我们可以取消Chrome吗?

<tr>
      <td style="width: 196px; height:40px">
                        <div id="FileAttached" style="font-size: xx-small;">
                            Attachments:
                            @if (Model.Attachment != null)
                            {
                                foreach (var a in Model.Attachment)
                                {   
                                    <div id="@a.FileName">@a.FileName<a href='#' title='delete' class="itemDelete">   delete</a></div>
                                }
                            }
                        </div>
                    </td>
                    <td>
                        @using (Html.BeginForm("EmailAttachment", "Message", new { messageID = Model.MessageID }, FormMethod.Post, new { enctype = "multipart/form-data", id = "emailForm", name = "emailForm", target = "UploadTarget" }))
                        {
                            <input type="file" name="attachment" />
                            <input type="button" class="InnerButton" style="float:right"; value="Upload Attachment" onclick="UploadAttachment()" />
                        }   
                        <iframe id="UploadTarget" name="UploadTarget" onload="UploadAttachment_Complete();" style="position: absolute; left: -999em; top: -999em;"></iframe> 
                    </td>
                </tr>

以下是我的功能

function UploadAttachment() {
    $("#emailForm").submit();
}
var isFirstLoad = true;
function UploadAttachment_Complete() {
    // First load of the iFrame?
    if (isFirstLoad == true) {
        isFirstLoad = false;
        return;
    }
    document.getElementById("emailForm").reset();
    //Grab the content of the textarea we named jsonResult . Loaded into the iFrame and carries values into variable for access.
    var newEmailAttachment = $.parseJSON($("#UploadTarget").contents().find("#jsonResult")[0].innerHTML);
    // Display errors
    if (newEmailAttachment.IsValid == false) {
        jAlert(newEmailAttachment.Message);
        return;
    }
    // Shovel the name of the attached file into a div presented below the attachment textbox.
    $("#FileAttached").append('<div id="'+ newEmailAttachment.Name + '">' + newEmailAttachment.Name + '<a href="#" title="delete" class="itemDelete">   delete</a></div>');
}

0 个答案:

没有答案