0

I am using a FileContentResult method to fetch a byte array from the database and render an image in the view. Works great but I can't figure out how to add an image alt tag (it would be the record name associated with the database record). I can either pass the name into the FileContentResult method or retrieve it from the database with the byte array and file type.

This is my return statement from the FileContentResult method:

return File(imageBinary, fileType);

This is my image tag from the view:

@foreach (var i in Model.Items)
{
   <li>
        <img src="@Url.Action("GetCatalogImage", "Gallery", new {ID=i.ItemID, Entity="item", Size="t" })" />
   </li>
}
tereško
  • 56,151
  • 24
  • 92
  • 147
GDB
  • 2,365
  • 2
  • 23
  • 31

1 Answers1

2

I'm not sure if what you are asking is possible. It would seem that, given you know the item ID when you populate the model in the first place, you could also at that point look up the alt tag (presumably stored in the database) and then pass that via the view model.

<img alt="@i.Alt" src="@Url.Actio....

I apologise if you have already thought of this solution and thought it not suitable!

MaxRev17
  • 283
  • 3
  • 10
  • Thanks! That's exactly what I needed to do; I was getting the syntax wrong. Here's the correct image tag: @i.Name – GDB Dec 09 '13 at 23:59
  • No problem! Thought it was worth a punt in case it was a nudge in the right direction :) – MaxRev17 Dec 10 '13 at 00:30