在ASP中的MVC,我怎么能返回一个新的视图和文件到用户? [英] In ASP MVC, how can I return a new view AND a file to the user?

查看:117
本文介绍了在ASP中的MVC,我怎么能返回一个新的视图和文件到用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想既然我已经江郎才尽我会对这对StackOverflow的人群。

Thought I would pose this to the StackOverflow crowd since I've run out of ideas.

我有,一旦按钮被点击,将生成一个PDF格式的用户,他们想自动观看请求,并且一旦它们关闭PDF页面将已经是最终页,而不是他们的页面从点击的按钮。

I have a request from users that once a button is clicked, a PDF form is generated which they would like to automatically view, and once they close the PDF the page will already be a "Final page", not the page they clicked the button from.

在与按钮我的pre-最后一页上,控制器调用:

In my pre-final page with the button, the controller calls:

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

但是,这目前已经通过了控制到客户端,我不能路线不同的看法。

But this has now passed the control to the client, I can't route to a different View.

我怎么还可以显示一个新的看法?上的任何巧妙的构思

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

推荐答案

我已经打破下来到对家庭控制器两个独立的操作,使用FinalPage行动的看法,你重定向到和的GetFile行动之一返回文件本身。

I've broken this down into two separate actions on the Home Controller, using the FinalPage action as the view you get redirected to and the GetFile action as the one to return the file itself.

控制器

    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();" }) %>

这将打开一个新窗口,得到的文件恢复显示,同时也移动其他浏览器窗口到最后一页上相同的点击。

This will open up a new window and get the file returned to display, but also move the other browser window onto the final page on the same click.

希望这有助于。

修改

更新流掉一个提交按钮按评论...在回答评论,是的,你可以做到这一点了一个提交按钮: - )

Updated to run off a submit button as per comment ... in answer to the comment, yes you can do it off a submit button :-)

<script>

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

</script>

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

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

<% } %>

希望这有助于: - )

Hope this helps :-)

这篇关于在ASP中的MVC,我怎么能返回一个新的视图和文件到用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆