开发者

how to open a page in another browser instance by clicking on a link

i have a link

<a id="DownloadLink" href='controller/action' target="_blank">Download File</a>

that has to open a image in another tab or page. but it offers me to download the file.

my action looks like this

public FileContentResult GetSurveyFile(int Id)
        {
  开发者_如何学编程          if (Id == 0)
                return null;
            Survey survey = Repository.GetItem(Id);
            if (survey.File == null)
                return null;

            return File(survey.File.FileContent.ToArray(), survey.File.ContentType,survey.File.Name);
        }

where the content type is an image/jpeg

whats wrong?


How a browser handles image files is up to the browser/OS/user preferences. To absolutely guarantee that it is opened and not downloaded, simply wrap the image in and html page where the image is the only thing in the body.


Nothing is wrong with this - if you send data to a browser with a mime type set, it may decide to offer a download rather than display the content. Most browsers are set up to download MP3 files, for example.

In your scenario, the browser is deciding to download the image.

You can display it by embedding it inside of an HTML page - this will ensure it displays in all browsers, rather than downloading - and the user can use the normal methods to save the image from the web page if they wish.

...
<body>
    <img src="your-c#-page" />
</body>
....
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜