我想返回一个显示在新页面上的ActionResult吗? [英] I would like the return of an ActionResult displayed on a new page?

查看:333
本文介绍了我想返回一个显示在新页面上的ActionResult吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想返回在新页面上显示的ActionResult吗?

I would like the return of my ActionResult Displayed on a new page?

以下是我唯一无法在新页面上显示的电话?

This call below is the only call i have not been able to display on a new page?

任何人都可以告诉我要添加什么来实现此目的吗,我已经使用Window.open并带有按钮,但是现在我有了RedirectToAction.

Can any one show me what to add to get this right, i have used Window.open with buttons but now i have a RedirectToAction.

这是我要在新页面/窗口上显示的呼叫:

return RedirectToAction("Print", new { id = contractInstance.SalesContractId });

我已经有一些使用此代码的按钮:

window.open('Contract/Print/' + $(this).attr('id'));

打印操作结果如下:

public ActionResult Print(int id) // sales contract Id
        {
            ParameterFields paramFields = CreateParameterFields(id); // pass the id of the contract
            // Save the report run details
            Guid reportRunId;
            SaveReportRunDetails(paramFields, out reportRunId);               

            try
            {

               <<< Print code >>>
//Open a new page on this return would also be a good answer :)!!!!!!!
                return File(arrStream, "application/pdf");
            }
            catch (Exception err)
            {
                ViewBag.ErrorMessage = err.Message;
                return RedirectToAction("Edit", new { id = id, error = err.Message }); 
            }
        }

推荐答案

您如何从视图中执行打印"操作?仅仅是超链接@Html.ActionLink("Print", "Print")吗?

How are you getting to the Print action from your Views? Is it just a hyperlink @Html.ActionLink("Print", "Print")?

.NET无法告诉您的浏览器从服务器打开新窗口,这是通过HTML标记或javascript调用(例如Window.Open)在客户端完成的.在新页面中打开链接的最简单方法是在HTML上指定目标属性.使用ActionLink帮助器,您的语法将是:

.NET cannot tell your browser to open a new window from the server, that is done client side via the HTML markup or javascript calls (eg. Window.Open). The easiest way to open a link in a new page is to specify the target attribute on the HTML. Using the ActionLink helper, your syntax would be:

@Html.ActionLink("Print", "Print", "Contract", new{id = Model.SalesContractId}, new {target = "_blank"})

这应该呈现如下内容:

<a href="/Contract/Print/4" target="_blank">Print</a>

这篇关于我想返回一个显示在新页面上的ActionResult吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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