This is post is more about me asking the question then giving direction on best practice.
The question is simple. When dealing with viewdata with the MVC framework, what type of usage of viewdata is preferred?
If you watch Scott's screencasts it appears the he favors the use of a property object that is unique to each view. This property object would hold onto the various objects needed by the view. By using this method, you are assured that the view is typed.
i.e. public partial class SomeView : ViewPage<SomeViewPropertyBag>
This method allows for the view to be strongly typed, but also would require that you actually have a shell of a code behind class as well as a special class for each view.
The other approach that I have seen is from the CodeCampServer guys. They have implemented their own 'smartbag' (a typed hashtable) which they use as a catch all object to be used by the view. In this case the developer is getting data out of the smart bag blindly (meaning they are not 100% assured that the object type they want/need is actually meant to be stored in the smartbag for that view). This method does NOT require the use of a codebehind page though, so that could be a plus for some. It also does not required a special class for each view, this could also be a plus.
Thoughts, feedback. Just wondering here.
Till next time,
03-06-2008 8:55 PM