currently I have a byte array representing my Image in my ViewModel. I display it with the following code:
<img src="@String.Format("data:image/gif;base64,{0}", Convert.ToBase64String(Model.Image))" />
Now I don't want to have a Base64 String in my Source file, but rather a link to a image. Like:
<img src="Images/" + Model.Id"/>
which would return a Image.
How do I write such a method to return a Image link?
You could define a controller action that will serve the image:
and in your view simply point the
src
property of theimg
tag to this controller action:One way is to add this to a new c# class or HtmlExtensionsclass
then you can do this in any view