title: Web Api How to Return Dynamically Created Image and text data simultaneously in same response
body: <p>I would like to return an image that is dynamically created instead of retrieving from a database or from file. Let's say I have a simple ZipCode class. I would like to have a property that would return an image representation of the zipcode. The JSON returns "ZipAsImage":"System.Drawing.Bitmap".
  Yes I am new to the programming in the web world. Yes I have looked for other examples but they seemed to only return an image. Thanks for any help.</p>
  
  <pre><code>public class ZipCode
  {
      public int ZipCodeId { get; set; }
      [NotMapped]
      public Image ZipAsImage
      {
          get
          {
              // Create a blank iamge for now to test.
              return new Bitmap(50, 50);
          }
          set { }
      }
  }
  </code></pre>
  
  <p>My ApiController class</p>
  
  <pre><code>public class ZipCodesController : ApiController
  {
      private MyContext db = new MyContext();
  
      // GET api/ZipCodesController
      public IEnumerable&lt;ZipCode&gt; GetZipCodes()
      {
          return db.zipcodes.AsEnumerable();
      }
  
      // GET api/ZipCodesController/5
      public ZipCode GetZipCode(int id)
      {
          ZipCode zipcode = db.ZipCodes.Find(id);
          if (zipcode == null)
          {
              throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
          }
  
          return zipcode;
      }
  ...
  </code></pre>
  
  <p>My Controller class</p>
  
  <pre><code>public class ZipCodesController : Controller
  {
      private MyContext db = new MyContext();
  
      //
      // GET: /ZipCodes/
  
      public ActionResult Index()
      {
          var zipcodes = db.ZipCodes.Include(z =&gt; z.State);
          return View(zipcodes.ToList());
      }
  
      //
      // GET: /ZipCodes/Details/5
  
      public ActionResult Details(int id = 0)
      {
          ZipCode zipcode = db.ZipCodes.Find(id);
          if (zipcode == null)
          {
              return HttpNotFound();
          }
          return View(zipcode);
      }
  ...
  </code></pre>