0

Im my asp.net mvc application I have a

  • enclosing the thumb image of the file in an aspx page loaded in an iframe. I want to open the file with an Open/Save dialogbox. The file is uploaded to the database in image datatype. My aspx page has the following html in it:
    <li class="thumpimage">
                            <%=Html.Hidden("attachmtId", item.ILDAttachmentId) %>
                            <img src="<%=imgurl %>" alt="test" height="81" width="76" />
                            <span class="thumb_descrp">
                                <%=item.ILDAttachmentName %></span></li>
    

    The jquery part is as follows

    $(document).ready(function() {
    
            $(".thumpimage").click(function() {
                var attchmtId = $("#attachmtId").val();
                alert(attchmtId);
                $.post('/Instruction/OpenInstnDoc', { attchId: attchmtId });
            });
        });
    

    And the function in the controller is

     public ActionResult OpenInstnDoc(int attchId)
        {
    
            Attachment objAttach = new Attachment();
            objAttach = objAttach.GetAttachmentById(attchId);
    
            byte[] theData = objAttach.BinaryFile;
            Response.AddHeader("content-length", theData.Length.ToString());
            Response.AddHeader("content-disposition", "inline; filename=" + objAttach.AttachmentName + "");
            return File(theData, objAttach.MineType);
        }
    

    I am not able open the file. Can anyone help me on this?

  • sujanr
    • 13
    • 5
    • What is `File`? (Clearly not `System.IO.file` – it is a static class.) What error/exception are you getting? – Richard Aug 10 '11 at 06:56
    • file is FileContentResult File(byte[] fileContents, string contentType). Am not getting any exception. Also no Open/Save dialog box – sujanr Aug 10 '11 at 07:00

    1 Answers1

    0

    You cannot use ajax to stream file content to the browser and expect to be prompted with a file open/save dialog. Instead of the call to $.post, try

    $(document).ready(function() {
    
        $(".thumpimage").click(function() {
            var attchmtId = $("#attachmtId").val();
            alert(attchmtId);
            //$.post('/Instruction/OpenInstnDoc', { attchId: attchmtId });
            window.location.href = "/Instruction/OpenInstnDoc/" + attchmtId;
        });
    });    
    
    RoccoC5
    • 4,185
    • 16
    • 20
    • I got an Object reference error in the page loaded to the iframe. – sujanr Aug 10 '11 at 09:29
    • You are receiving a javascript error? I updated my post to include the full document.ready function. Is the alert popping up? – RoccoC5 Aug 10 '11 at 15:02