开发者

Use a System.Data.Linq.Binary object as an HTML image source

I'm using ASP.NET MVC and have a model that has System.Data.Linq.Binary property. The property represents a picture that has been stored in the database as an image column.

I am able to use the picture in my pages by setting up a separate controller action and using Response.OutputStream.Write to dump the Binary object and then setting the controller action as an HTML img source.

I'm wondering if there is any way to use a Binary object directly in a view without needing the separate controller action? The idea would be to achieve the below which I know will not开发者_Python百科 work but it demonstrates what I'd like to be able to do.

<img src="<%= Model.MyBinaryProperty%>" />


By nature of the problem, no.

You can simulate it, but you will always be relying in a separate request that serves the image.

There are just too many options, some:

  • Use a regular asp.net handler
  • Only retrieve on the separate request vs. Store somewhere temporarily and serve from there during the request. Usually the earlier is best
  • Use a controller action
  • Depending on the load characteristics and only if really needed, serve the image download from a different server
  • Setup a route + routehandler that serves the image
  • Setup an action filter that by some convention handles serving the image without needing to explicitly define the separate action method.
  • I'm sure there are others ...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜