Friday, March 18, 2016

serve up an image with @Url.Action

In an ASP.NET MVC application, your action could look like:

public ActionResult Image()
{
   byte[] bytes;
   using (StringReader stringReader = new StringReader(Images.Plane()))
   {
      XmlSerializer xmlSerializer = new XmlSerializer(typeof(byte[]));
      bytes = (byte[])xmlSerializer.Deserialize(stringReader);
      return File(bytes, "image/jpg");
   }
}

 
 

And, in your view you would have:

<img src="@Url.Action("Image", "Home")"/>

No comments:

Post a Comment