aha*_*sky -1 c# asp.net-mvc asp.net-web-api asp.net-web-api2
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_;
Run Code Online (Sandbox Code Playgroud)
您不需要对此操作进行 AJAX 调用。只需放置一个<img>标记并将其 src 属性指向您的 Web API 端点:
<img src="api/account/GetImageByAccountId/12345" alt="" />
Run Code Online (Sandbox Code Playgroud)
或者,如果您accountId事先不知道,您可以img动态构建此标签并使用 javascript 将其注入 DOM:
var id = '12345';
$('#someDivId').prepend('<img src="api/account/GetImageByAccountId/' + id + '" alt="" />');
Run Code Online (Sandbox Code Playgroud)
并且图像将添加到您需要在 DOM 中的容器中:
<div id="someDivId"></div>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6625 次 |
| 最近记录: |