First of all
Url.Action("RenderPhoto", Model.Photo)
Does not work, Model.Photo (presumably your byte array) will be considered as an object for determining route values. It will generate a route with the public properties of the Array object, possibly line by line
?IsFixedSize=true&IsReadOnly=false&Length=255
This will be a pretty useless URL. When the page loads in the browser, the browser requests this image by calling your RenderPhoto method, but there is no parameter called a photograph, so the binding will fail, and even if there was a parameter called a photograph (AFAIK) in DefaultModelBinder to create an array of bytes from a string, so the photo is null.
What you need to do is pass an anonymous object with the Id property to Url.Action
Url.Action("RenderPhoto", new { Id = Model.PhotoId })
This will be converted to a query, perhaps along the lines of the following (but it depends on your routes)
/xxx/RenderPhoto/25
And then you will need to return the data for the photo to your RenderPhoto method
Martin
Martin booth
source share