C#MVC:Chrome使用操作名称设置嵌入式PDF标题 [英] C# MVC: Chrome using the action name to set inline PDF title

查看:176
本文介绍了C#MVC:Chrome使用操作名称设置嵌入式PDF标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个动作,他会在新的浏览器标签中显示PDF.

I have an action who displays a PDF in a new browser tab.

    public ActionResult Print()
    {
        var cd = new ContentDisposition
        {
            FileName ="something.pdf",
            Inline = true 
        };
        Response.AppendHeader("Content-Disposition", cd.ToString());
        return File(reportResponse.Data.Document, MediaTypeNames.Application.Pdf);

    }

文件名工作正常.当我下载文件时,它的名称是我想要的"something.pdf".

The filename is working fine. When I download the file it has the name I want "something.pdf".

问题是,当Google chrome在新的浏览器标签中打开PDF时,它将显示控制器操作名称(打印)作为PDF的标题.那就是我要改变的东西.我附上一张图片进行说明.

The problem is when google chrome opens the PDF in a new browser tab, it displays the controller action name (Print) as the title of the PDF. That's what I'm trying to change. I attached a picture for clarification.

查看代码: Url.Action("Print","Controller",new {area ="Area"}),new {@target ="_blank"}

View code: Url.Action("Print", "Controller", new { area = "Area" }), new { @target = "_blank" }

推荐答案

向操作方法传递文件名的参数,并确保参数名称为'id'.

To the action method pass parameter of the file name and make sure parameter name is 'id'.

查看代码:

Url.Action("Print", "Controller", new { id = "filename", area = "Area" }), new { @target = "_blank" }

这篇关于C#MVC:Chrome使用操作名称设置嵌入式PDF标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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