【问题标题】:Images displayed through Hyperlink on an MVC View通过 MVC 视图上的超链接显示的图像
【发布时间】:2012-12-30 19:46:07
【问题描述】:

我有一个 MVC3 应用程序,它有一个带有表格的视图和点击链接以显示图像。由于大小,客户不希望图像直接显示在网格中。

我将图像存储在 SQL Server 数据库中。我见过的从数据库中检索 byte[] 并显示它的每个示例都涉及首先保存到文件。有没有办法通过内存流来响应。直接写入并绕过文件 i/o?

【问题讨论】:

  • 我也尝试将 byte[] 转换为 base64string 并将其传递给 url.action,但它给我的 URI 操作太长了...

标签: asp.net-mvc-3 image-processing


【解决方案1】:

请查看此答案Display image from database in asp mvc

而不是使用图像

<img src='<%= Url.Action( "show", "image", new { id = ViewData["imageID"] } ) %>' />

使用和操作链接

@Html.ActionLink("View Image", "Action", "Controller", new { id = ViewData["imageID"] } )

只需将 ViewData["imageID"] 替换为图像的 id

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-23
    • 2018-06-17
    • 2016-09-04
    相关资源
    最近更新 更多