开发者

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

开发者 https://www.devze.com 2022-12-23 14:25 出处:网络
i have a link <a id=\"DownloadLink\" href=\'controller/action\' target=\"_blank\">Download File</a>

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

精彩评论

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