【发布时间】:2014-04-30 14:44:19
【问题描述】:
我有一个 ASP.NET MVC 项目,它有一个返回图像的控制器方法...
public ActionResult SpeakerImage(int id) {
Speaker speaker = _speakersServiceLogic.GetByID(id);
if (speaker != null) {
return File(speaker.Picture, "image/jpg");
}
return null;
}
如何在 HTML img 标签中使用它?我知道我可以硬编码 src 属性...
<img src="/Speakers/SpeakerImage/@Model.ID" />
...但是如果控制器动作被移动,这将中断。
我想知道是否有更好的方法来做到这一点。要创建链接,我可以使用 Html.ActionLink,它将为我创建 HTML。 <img> 有类似的吗?
【问题讨论】:
标签: html asp.net-mvc