barnacle.m
barnacle.m

Reputation: 2200

Excel file downloads instead of displaying in iframe

I have this in my controller class:

    public ActionResult ExcelDoc()
    {
        var doc = Server.MapPath("~/Content/Sheet1.xlsx");
        return File(doc, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
    }

And in my view:

<iframe src="/Centres/ExcelDoc"></iframe>

It simply DOES NOT display the file in the iframe. Instead, it begins downloading sheet1.xlsx as ExcelDoc.xlsx. Very frustrating as previous questions have helped me to develop this solution to my previous problem of trying to display a dynamically generated excel file in an iframe. I am using Google Chrome, if that is relevant.

Upvotes: 0

Views: 1948

Answers (1)

Piet van Dongen
Piet van Dongen

Reputation: 1639

Returning a file makes your browser try to download it, that's expected behaviour. I think it's not possible to display an excel file as-is in your browser window, unless you use something like a plug-in.

Upvotes: 1

Related Questions