MemoryStream to IMG via TempData in MVC3 - is there a better way?

后端 未结 1 852
挽巷
挽巷 2021-01-16 00:27

A Model contains, amongst other properties, a method which returns an MSChart as a MemoryStream.

In my View I copy the MemoryStream to TempData[\"Chart\"] and then u

1条回答
  •  礼貌的吻别
    2021-01-16 01:16

    The acedemic way would be to retrieve the model object again in the RenderChart action and return the chart image to the view.

    But i think its a valid approach to store the image in TempData for reducing database roundtrips and boosting performance.

    Maybe its even unnecessary to improve the performance. The database will have the data available in its cache when reading it the second time and the additional 10ms needed to fetch the data again might not be noticeable by the user.

    At least TempData seems to be the right store because the value is deleted from the collection when its read by the RenderChart action.

    0 讨论(0)
提交回复
热议问题