在 asp.net mvc 项目中,我如何使用 iframe 来显示文档文件? 我尝试在下面的代码中执行类似的操作,但是当我运行项目文件时已下载...为什么?
public FileStreamResult GetPDF()
{
FileStream fs = new FileStream(Server.MapPath(@"~/File/SegmentAdd.txt"), FileMode.Open, FileAccess.Read);
return File(fs,"application/pdf","SegmentAdd.txt");
}
<iframe src="@Url.Action("GetPDF","Home")" width="90%" height="90%"></iframe>
最佳答案
修改代码如下
public FileStreamResult GetPDF()
{
FileStream fs = new FileStream(Server.MapPath(@"~/File/SegmentAdd.txt"), FileMode.Open, FileAccess.Read);
return File(fs, "text/plain");
}
实际上.txt文件的内容类型是
text/plain
希望这对你有帮助
更新
为了了解每种文件类型的内容类型请引用MIME Type list
关于javascript - 如何使用 ASP.NET MVC 在 iframe 中显示文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37935957/