Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4530704
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T13:49:46+00:00 2026-05-21T13:49:46+00:00

I am calling an ajax.action link on a page. This will display the name

  • 0

I am calling an ajax.action link on a page. This will display the name of the document. While i click on the document, an ajax request is fired tot he controller, which will return a File Content Result and I want this file to be shown inline in the browser under the targetID div.

Code – bytestream = fs.ToArray();
fs.Close();
Response.AppendHeader(“Content-Disposition”, String.Format(“inline; filename={0}”, fileName));
return File(bytestream, “application/pdf”);

The problem is , the file is displayed as the stream and it is not displying the contents correctly.

    <legend>Document</legend>
    <% if (Model.PresentDocument != null)
       { %>
    <li><%: Ajax.ActionLink(Model.PresentDocument, "GetDocumentPage", new RouteValueDictionary(new { controller = "Document", action = "GetDocumentPage", id = Model.PresDocId }), new AjaxOptions { HttpMethod = "Post", UpdateTargetId = "Document" })%></li>
    <%} %>
    <div id="Document">
    </div>

Do i need to do anything specific for this div to display the inline pdf?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T13:49:47+00:00Added an answer on May 21, 2026 at 1:49 pm

    You cannot use AJAX to download files. One possible way to achieve this is to have a normal link and when this link is clicked use javascript to dynamically generate an iframe and point the iframe source to the controller action:

    <%= Html.ActionLink(
        Model.PresentDocument, 
        "GetDocumentPage", 
        "Document",
        new { id = Model.PresDocId }, 
        new { id = "displayPdf" }
    ) %>
    

    which is you could AJAXify like this (using jQuery):

    $(function() {
        $('#displayPdf').click(function() {
            $('#Document').html(
                $('<iframe/>', {
                    src: this.href,
                    width: '300px',
                    height: '150px'
                })
            );
            return false;
        });
    });
    

    which assumes that your controller action is accessible through GET requests:

    public ActionResult GetDocumentPage(string id)
    {
        byte[] pdf = ...
        Response.AppendHeader("Content-Disposition", String.Format("inline; filename={0}", fileName));
        return File(pdf, "application/pdf");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Iam using cakephp ajax link for calling a page <div id=post> </div> <?php echo
I am calling a controller's create action via ajax so when the object saves
I'm working on a javascript function that when called will make a ajax request
I have a link which dispatches an Ajax POST to perform an action. If
HI, i need to pass id=2 while calling the action method ? How can
I'm making paypal request using Ajax calling but I'm getting error with status ZERO.The
The Ajax request is as follows: In the controller action method I tried to
I'm trying to redirect to another page by calling an action in controller with
I'm calling a view after an AJAX POST action. But I'm loading the view
i am calling struts2 action from jquery ajax on success it returns string and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.