I am creating a website with MVC 4. For project requirements, the images are stored in database. I have a View that I bind the Model in which I have the Id of the picture accompanying the story, then I get the image:
View:
<img src='<%= Url.Action("ShowImagen", "Home", new {id = item.IdImagen}) %>' style="width: 300px;
height: 200px;" />
Controller:
public FileResult ShowImagen(int id)
{
if (id > 0)
{
var imageData = new NoticiaRepository().GetImagen(id);
return File(imageData, "image/jpg");
}
else
{
return null;
}
}
With this and checking it with Chrome, I've noticed that when I reload the page, It not load the images from the cache, like other files as .css or other images loaded from file system.
Is there any way to make these images are cached? A greeting and thanks.
You could decorate your
ShowImagen
controller action with the[OutputCache]
attribute:Have you tried decorating your action method with
OutputCache
attribute?