return an image using ASP.NET Web API and display it?
问题 web api action : byte[] bytes = System.IO.File .ReadAllBytes( HttpContext.Current.Server.MapPath("~/Images/orderedList1.png")); var result_ = new HttpResponseMessage(HttpStatusCode.OK); result_.Content = new ByteArrayContent(bytes); result_.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png"); return result_; Ajax call respond - data in console 回答1: You don't need to make an AJAX call to this action. Just put an <img> tag and point its src property to your Web API endpoint: