MVC @Url.Action 小示例

功能说明:从Action获取图片路径,页面显示图片

页面:

<img src="@Url.Action("ImagePath", new { id="1"})"  />

后台代码:

public ActionResult ImagePath(string id)
{
string path = Server.MapPath("/Content/Images/" + id + ".jpg");

return File(path, "image/png");
}

部分截图:

  效果图:

以前没用过Url.Action 函数,今天偶遇,记录一下;希望能帮助到你!

原文地址:https://www.cnblogs.com/czqbk/p/5063964.html