I was just wondering if it possible to make an ajax request from a view to an action which injects image data directly in to an image tag.
To give more details, i am borrowing some code in stackoverflow.
Controller;
public FileResult GetImage(int id)
{
return File(PhotoHelper.GetImageBytes(id), "image/jpeg");
}
View:
<%= Html.Image("img", "/Photos/GetImage?id=" + Model.Photo.Id.ToString(), "BioPic", new { Width = "350px" })%>
Is it possible to load another another image from GetImage(int ID) using ajax?
Any HttpRequest that routes to the GetImage() method will produce a jpeg image. If you dynamically create another image tag using javascript and set it’s src attribute to “/Photos/GetImage?id=x” another HttpRequest will be made to this controller, and another image will be created.
EDIT: You tagged jquery in your post, so here’s the jquery for something like this: