Thursday, November 8, 2012

ASP.NET MVC generates error = "OutputStream is not available when a custom TextWriter is used"

In a simple application I'm creating, I have a custom ActionResult class that returns an image data. In my view, I simply used:
1:  <%= Html.Action("GetImage", "ImageCustom", new{id = item.CategoryID}) %>  
to call the custom action class ExecuteResult method. This method reads the image byte array and store's it in a stream object. However, the call generates an error stated in the title. Html.Action writes html which implements text writer class. The solution would be using Url.Action() embedded in the image src attribute:
1:  <img src='<%= Url.Action("GetImage","ImageCustom", new {id = item.CategoryID}) %>'   
2:  alt="No Photo" width="100" height="100" />  


Post a Comment