要在ASP.NET Core 2.2 MVC中查看内联文件时显示自定义文件名,您可以使用Content-Disposition标头来指定文件名。以下是实现这一点的代码示例:
public IActionResult DownloadFile()
{
// 获取文件内容
byte[] fileContents = GetFileContents();
// 设置文件名
string fileName = "customfilename.txt";
// 设置Content-Disposition标头
Response.Headers.Add("Content-Disposition", new[] { "attachment; filename=" + fileName });
// 返回文件结果
return new FileContentResult(fileContents, "application/octet-stream");
}
下载文件
当您单击该链接或按钮时,将触发DownloadFile
方法,并将文件下载到浏览器。浏览器将使用指定的文件名customfilename.txt
进行保存。
这样,您就可以在ASP.NET Core 2.2 MVC中查看内联文件时显示自定义文件名了。