I have a ViewPage, Index.aspx. In it, I have:
<%= Html.Partial("~/Index/ViewUserControl/Promo.ascx, new PromoViewModel()); %>
Now, the constructor for PromoViewModel requires a MemcachedCache object that the index's controller also uses.
How should I pass this MemcachedCache into my partial view?
Should I put the MemcachedCache instance in the ViewData and do this?
<%= Html.Partial("~/Index/ViewUserControl/Promo.ascx,
new PromoViewModel(ViewData["cache"] as MemcachedCache)); %>
Index.aspx isn't a strongly-typed view; it doesn't use a view model. But should I strongly-type it with a view model that has a public Cache member, then access it through the Model?
<%= Html.Partial("~/Index/ViewUserControl/Promo.ascx,
new PromoViewModel(Model.Cache); %>
Now I find out with MVC3, there's a third option: I can set a ViewModel member in the index controller with the Cache member, and use it like this:
<%= Html.Partial("~/Index/ViewUserControl/Promo.ascx,
new PromoViewModel(ViewModel.Cache); %>
Which is more appropriate? This seems a little confusing/silly to me.