I use an EditorTemplate to render the collection of images in the View, which makes a call to my Controller for each image. Here's the Razor code that calls the Controller method :
Code: Select all
<div>
<img style="border: solid; border-color: lightgrey; border-width: thin" src="@Url.Action("GetImages", "Product", new {docId = Model.DocumentID, width = 250, height = 250})" alt=""/>
</div>
Code: Select all
public void GetImages(int docId, int width, int height)
{
// Load image from database
var document = prodRepository.Documents.SingleOrDefault(f => f.DocumentID == docId);
var image = document.FileContent;
new WebImage(image)
.Resize(width, height, true, true)
.Crop(1, 1)
.Write();
}
Code: Select all
public IQueryable<Document> Documents
{
get { return prodContext.Documents; }
}
public IDbSet<Document> Documents { get; set; }
Cheers,
Ciaran