1

I'm working on implementing change profile picture feature in ASP.NET MVC 5 application. I'm a beginner so please forgive me if I'm not specific enough.

The picture appears in the header and sidebar (partial views) as well as on the actual page. The picture is loaded from a specific location on the server: img/Users/userName.jpg. When I upload the new one using API controller the file is overwritten. Still the picture displayed on the page remains the same until I refresh the entire website.

Question: Is it possible to dynamically reload just the elements using the file, so the new picture is displayed automatically without calling window.location.reload(); ? Can you please explain how such thing could be achieved? Or at least point me in the right direction?

Thanks a lot. Please let me know if the question is understandable and if you require additional detail concerning the application.

Stefan
  • 17,448
  • 11
  • 60
  • 79
Zawiszor
  • 528
  • 4
  • 10
  • You a right, this is not specific enough, but have a look at this: http://stackoverflow.com/questions/1077041/refresh-image-with-a-new-one-at-the-same-url . I must say; there are a lot of ways to accomplish this. – Stefan Aug 20 '15 at 14:40
  • you can check Signal IR you could use it for getting instance response from server when update has been trigger. – DarkVision Aug 20 '15 at 16:45

1 Answers1

2

Do Cache busting via params. append some query string with random values

<img src="/img.png?c=1111">
Pavan Teja
  • 3,192
  • 1
  • 15
  • 22
  • I tried doing that, but because the source value is passed from the model I got some horrible problems with that. But let's say I managed to get that to work and the image din't cache, would that cause the images to update automatically, or would I have to trigger it somehow. If so what's the best way to trigger that update? Thanks :) – Zawiszor Aug 21 '15 at 12:27
  • Thanks so much! I pretty much did the same thing and it works: var cachbuster = DateTime.Now; – Rich Ward Dec 09 '15 at 20:50