I have an object Document that describes a file: the file is HTML format file.
public class FileObj
{
public string FileName;
public string MimeType;
public Stream File;
}
This is my controller Action
[HttpGet]
public ActionResult Open(Guid fileId)
{
var document = repository.GetFile(fileId);
return File(document.File, document.MimeType, document.FileName);
}
In the view there is a simple link like this:
<a href="/Documents/Open?fileId=1" target="blank" title="Click to download">open file</a>
Every time I click the link the file is downloaded. I want it to be opened by the browser in a new window instead.
How can I do it? I am working in ASP.NET MVC3
You need to specify a
Content-Disposition
header:Also, I think you're looking for
target="_blank"
. The attributetarget="blank"
will open in a window/tab named internally as "blank", and any further clicks will reload that window/tab instead of popping a new window/tab each time.