How to show a FileContentResult containing pdf data into browser












0















I have a byte array containing data of a pdf file which I have read from remote:



byte filedata = webClient.DownloadData(fPath);


I am sending the filedata from controller to view in an ajax call:



Response.Headers.Add("Content - Disposition", "inline; filename = test.pdf");
return File(files[0], "application/pdf");


I want to show that pdf file on the browser, I have created an element in my html but I don't know how to show the file.
Could somebody please help me with this?
Thanks










share|improve this question

























  • You will need to open the URL corresponding to that controller action.

    – Strikegently
    Nov 23 '18 at 11:59











  • won't the page reload in that case? I want to maintain the same web page and update just the embed section with the pdf file. Is that possible?

    – NoWayHandshake
    Nov 23 '18 at 12:02











  • You could look at a 3rd party js library maybe. I don't think you can do it just in mvc

    – ste-fu
    Nov 23 '18 at 12:09













  • Do you want to show the pdf in a new window, or the same one in some form of control?

    – R2D2
    Nov 23 '18 at 12:13











  • @R2D2 I want to show it in an embed element which is a html element that allows to show pdf files. And on the same page not another window.

    – NoWayHandshake
    Nov 23 '18 at 13:18
















0















I have a byte array containing data of a pdf file which I have read from remote:



byte filedata = webClient.DownloadData(fPath);


I am sending the filedata from controller to view in an ajax call:



Response.Headers.Add("Content - Disposition", "inline; filename = test.pdf");
return File(files[0], "application/pdf");


I want to show that pdf file on the browser, I have created an element in my html but I don't know how to show the file.
Could somebody please help me with this?
Thanks










share|improve this question

























  • You will need to open the URL corresponding to that controller action.

    – Strikegently
    Nov 23 '18 at 11:59











  • won't the page reload in that case? I want to maintain the same web page and update just the embed section with the pdf file. Is that possible?

    – NoWayHandshake
    Nov 23 '18 at 12:02











  • You could look at a 3rd party js library maybe. I don't think you can do it just in mvc

    – ste-fu
    Nov 23 '18 at 12:09













  • Do you want to show the pdf in a new window, or the same one in some form of control?

    – R2D2
    Nov 23 '18 at 12:13











  • @R2D2 I want to show it in an embed element which is a html element that allows to show pdf files. And on the same page not another window.

    – NoWayHandshake
    Nov 23 '18 at 13:18














0












0








0








I have a byte array containing data of a pdf file which I have read from remote:



byte filedata = webClient.DownloadData(fPath);


I am sending the filedata from controller to view in an ajax call:



Response.Headers.Add("Content - Disposition", "inline; filename = test.pdf");
return File(files[0], "application/pdf");


I want to show that pdf file on the browser, I have created an element in my html but I don't know how to show the file.
Could somebody please help me with this?
Thanks










share|improve this question
















I have a byte array containing data of a pdf file which I have read from remote:



byte filedata = webClient.DownloadData(fPath);


I am sending the filedata from controller to view in an ajax call:



Response.Headers.Add("Content - Disposition", "inline; filename = test.pdf");
return File(files[0], "application/pdf");


I want to show that pdf file on the browser, I have created an element in my html but I don't know how to show the file.
Could somebody please help me with this?
Thanks







javascript c# ajax asp.net-mvc






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 12:57









Uwe Keim

27.4k31129210




27.4k31129210










asked Nov 23 '18 at 11:57









NoWayHandshakeNoWayHandshake

64




64













  • You will need to open the URL corresponding to that controller action.

    – Strikegently
    Nov 23 '18 at 11:59











  • won't the page reload in that case? I want to maintain the same web page and update just the embed section with the pdf file. Is that possible?

    – NoWayHandshake
    Nov 23 '18 at 12:02











  • You could look at a 3rd party js library maybe. I don't think you can do it just in mvc

    – ste-fu
    Nov 23 '18 at 12:09













  • Do you want to show the pdf in a new window, or the same one in some form of control?

    – R2D2
    Nov 23 '18 at 12:13











  • @R2D2 I want to show it in an embed element which is a html element that allows to show pdf files. And on the same page not another window.

    – NoWayHandshake
    Nov 23 '18 at 13:18



















  • You will need to open the URL corresponding to that controller action.

    – Strikegently
    Nov 23 '18 at 11:59











  • won't the page reload in that case? I want to maintain the same web page and update just the embed section with the pdf file. Is that possible?

    – NoWayHandshake
    Nov 23 '18 at 12:02











  • You could look at a 3rd party js library maybe. I don't think you can do it just in mvc

    – ste-fu
    Nov 23 '18 at 12:09













  • Do you want to show the pdf in a new window, or the same one in some form of control?

    – R2D2
    Nov 23 '18 at 12:13











  • @R2D2 I want to show it in an embed element which is a html element that allows to show pdf files. And on the same page not another window.

    – NoWayHandshake
    Nov 23 '18 at 13:18

















You will need to open the URL corresponding to that controller action.

– Strikegently
Nov 23 '18 at 11:59





You will need to open the URL corresponding to that controller action.

– Strikegently
Nov 23 '18 at 11:59













won't the page reload in that case? I want to maintain the same web page and update just the embed section with the pdf file. Is that possible?

– NoWayHandshake
Nov 23 '18 at 12:02





won't the page reload in that case? I want to maintain the same web page and update just the embed section with the pdf file. Is that possible?

– NoWayHandshake
Nov 23 '18 at 12:02













You could look at a 3rd party js library maybe. I don't think you can do it just in mvc

– ste-fu
Nov 23 '18 at 12:09







You could look at a 3rd party js library maybe. I don't think you can do it just in mvc

– ste-fu
Nov 23 '18 at 12:09















Do you want to show the pdf in a new window, or the same one in some form of control?

– R2D2
Nov 23 '18 at 12:13





Do you want to show the pdf in a new window, or the same one in some form of control?

– R2D2
Nov 23 '18 at 12:13













@R2D2 I want to show it in an embed element which is a html element that allows to show pdf files. And on the same page not another window.

– NoWayHandshake
Nov 23 '18 at 13:18





@R2D2 I want to show it in an embed element which is a html element that allows to show pdf files. And on the same page not another window.

– NoWayHandshake
Nov 23 '18 at 13:18












1 Answer
1






active

oldest

votes


















0














I have a system that displays PDFs. I utilise a view that contains an IFrame. So suppose you have a button that says "View File", I have this open up the view that contains the IFrame. The source of the frame points to the controller action that returns your File result.



<iframe id="iframepdf" src="@Url.Action("ReturnMyFile", "MyController",
new { filePath = pathToFile})"></iframe>


You can pass the path as a variable to get the file bytes from where they are kept.
This then renders the Pdf within the IFrame



Hope that helps






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53446293%2fhow-to-show-a-filecontentresult-containing-pdf-data-into-browser%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I have a system that displays PDFs. I utilise a view that contains an IFrame. So suppose you have a button that says "View File", I have this open up the view that contains the IFrame. The source of the frame points to the controller action that returns your File result.



    <iframe id="iframepdf" src="@Url.Action("ReturnMyFile", "MyController",
    new { filePath = pathToFile})"></iframe>


    You can pass the path as a variable to get the file bytes from where they are kept.
    This then renders the Pdf within the IFrame



    Hope that helps






    share|improve this answer




























      0














      I have a system that displays PDFs. I utilise a view that contains an IFrame. So suppose you have a button that says "View File", I have this open up the view that contains the IFrame. The source of the frame points to the controller action that returns your File result.



      <iframe id="iframepdf" src="@Url.Action("ReturnMyFile", "MyController",
      new { filePath = pathToFile})"></iframe>


      You can pass the path as a variable to get the file bytes from where they are kept.
      This then renders the Pdf within the IFrame



      Hope that helps






      share|improve this answer


























        0












        0








        0







        I have a system that displays PDFs. I utilise a view that contains an IFrame. So suppose you have a button that says "View File", I have this open up the view that contains the IFrame. The source of the frame points to the controller action that returns your File result.



        <iframe id="iframepdf" src="@Url.Action("ReturnMyFile", "MyController",
        new { filePath = pathToFile})"></iframe>


        You can pass the path as a variable to get the file bytes from where they are kept.
        This then renders the Pdf within the IFrame



        Hope that helps






        share|improve this answer













        I have a system that displays PDFs. I utilise a view that contains an IFrame. So suppose you have a button that says "View File", I have this open up the view that contains the IFrame. The source of the frame points to the controller action that returns your File result.



        <iframe id="iframepdf" src="@Url.Action("ReturnMyFile", "MyController",
        new { filePath = pathToFile})"></iframe>


        You can pass the path as a variable to get the file bytes from where they are kept.
        This then renders the Pdf within the IFrame



        Hope that helps







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 12:55









        Wheels73Wheels73

        2,3161415




        2,3161415






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53446293%2fhow-to-show-a-filecontentresult-containing-pdf-data-into-browser%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Berounka

            Sphinx de Gizeh

            Different font size/position of beamer's navigation symbols template's content depending on regular/plain...