I want to serve images from a central location on my server. My image tags look like this:
<img src='@Url.Action("Image", "Home", new { id = "tt2119396.jpg" })' />
and in my HomeController the (experimental) action looks like this:
[AcceptVerbs(HttpVerbs.Get)]
public FileResult Image(string id)
{
var path = @"D:\Dropbox\MovieDB\TitleImages\" + id;
return new FileStreamResult(new FileStream(path, FileMode.Open), "image/jpeg");
}
However, the action Image is never called. I put a breakpoint on the first line and it never fires.
My routing definition is very simple, I don't think that is the issue:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}