简体   繁体   English

如何在浏览器 Mvc.net 中显示 doc 文件

[英]How to display doc file in browser Mvc.net

I have a Preview button on my page.我的页面上有一个预览按钮。 I want to display a .doc file in the browser when the user clicks on that button.当用户单击该按钮时,我想在浏览器中显示一个.doc文件。 I have written the code below, but it directly downloads the file instead of displaying it in the browser.我写了下面的代码,但它直接下载文件而不是在浏览器中显示它。

public FileResult ViewFile() {
        Response.AddHeader("content-disposition", "inline;filename=;");
        return File("~/Templates/chronoExp.doc", "application/msword");
} 

You will need some sort of control or library that's capable of showing the file type within the browser.您将需要某种能够在浏览器中显示文件类型的控件或库。 By default, browsers are not able to display an office document file (I believe PDF is the only document style that gets relatively decent support for embedded viewing across all browsers).默认情况下,浏览器无法显示办公文档文件(我相信 PDF 是唯一一种对所有浏览器的嵌入式查看支持相对不错的文档样式)。

In order to do this, look for some 3rd party tools or controls that would allow for this to work.为了做到这一点,请寻找一些可以使其工作的第三方工具或控件。 Such tools will involve passing the document to them and likely some server-side transformation and render to the control's browser display, so it's likely to be read-only.此类工具将涉及将文档传递给它们,并且可能会进行一些服务器端转换并呈现​​到控件的浏览器显示,因此它可能是只读的。

This answer provides a decent example of using Google's document viewer within an iframe: How do I render a Word document (.doc, .docx) in the browser using JavaScript?这个答案提供了一个在 iframe 中使用 Google 文档查看器的不错示例: How do I render a Word document (.doc, .docx) in the browser using JavaScript?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM