In ASP MVC, how can I return a new view AND file to the user?

I think I would put it on the StackOverflow crowd since I ran out of ideas.

I have a request from users that after clicking the button, a PDF form is created that they would like to automatically view, and as soon as they close the PDF, the page will already be the "Final Page", and not the page on which they click the button.

On my preliminary page with a button, the controller calls:

return File(finalForm, "application/pdf", Server.HtmlEncode(finalForm));

But now it has transferred control to the client, I can’t switch to another view.

Any clever ideas on how I can also display a new view?

+3
source share
2 answers

, FinalPage , , GetFile, , .

    public ActionResult GetFile()
    {
        return File(@"path to pdf.pdf", "application/pdf");
    }

    public ActionResult FinalPage()
    {
        return View();
    }

<script>

    function showfile() {
        window.open('<%= Url.Action("GetFile", "Home")%>')
    }

</script>

<%= Html.ActionLink("click", "FinalPage", "Home", null, new { onclick = "return showfile();" }) %>

, .

, .

Edit

... , , : -)

<script>

    function showfile() {
        window.open('<%= Url.Action("GetFile", "Home")%>')
    }

</script>

<% using(Html.BeginForm("FinalPage", "Home")) { %>

    <input type="Submit" value="click" onclick="return showfile();" />

<% } %>

, : -)

+6

WestDiscGolf, '_self':

function showfile() {
        window.open('PATH','_self')
    }
+1

Source: https://habr.com/ru/post/1763692/


All Articles