0

I have an image in asp.net mvc. On the click of the image the image should be downloaded and a counter (counting the number of downloads on the image should be incremented). I have done both of them separately.

However, is it possible to specify more than one url in the href attribute of the image?

I currently have this, image download on the click of the image

<a href="@Url.Content('https://someurl.com')"/>

And the controller action to increment the downloads counter is as follows:

<a href='@Url.Action("ActionName", "ControllerName")/>

Where ActionName is the name of the controller in the ControllerName which updates the increment of the downloads counter.

How can the download and the increment of the downloads counter happen simultaneously? Thanks

Spider Man
  • 415
  • 4
  • 10
  • 26
  • 3
    I would suggest to use only one action that would do both things. Your action in the second snippet can return an image as a response after incrementing the counter. – Jakub Rusilko Nov 22 '16 at 06:47
  • @JakubRusilko is totally right. An action can save the download count and can return File. You can have a look at this as an example. http://stackoverflow.com/questions/3007652/asp-net-mvc-download-image-rather-than-display-in-browser – mr. Nov 22 '16 at 06:58
  • Thanks @mayk for looking into this, but wouldn't it be better in my case if I could just update the counter first and simultaneously download the image. I looked into the other answer and its a way of controlling the download / display of the image. in my case the default action on the image should be download. Moreover, in my application I might be download a file of different format (say pdf) but only displaying the thumbnail of the resource as an image. – Spider Man Nov 22 '16 at 07:03

0 Answers0