I don't think that usage of TempData in views is a good idea.
I don't think that usage of TempData in views is a good idea.
Why not? The controller is still populating that collection of data. I don't think it really makes a difference whether you get it from ViewData or TempData.
I didn't know about that attribute in MvcContrib -- but still, I'd rather not have to decorate my controller with an arbitrary attribute just to support this scenario.
The reason I was expecting this behavior is that I was using Spark with Monorail before, and the <viewdata /> element in the Monorail Spark engine pulls from PropertyBag and Flash (equivalent of ViewData and TempData) and I don't see why it should be different for the MVC engine.
On Mon, Sep 14, 2009 at 12:10 PM, zihotki <zih...@gmail.com> wrote:
I don't think that usage of TempData in views is a good idea. IMO,
views should use data from ViewData only. And all necessary data for
the view should be added to the ViewData. Views should know nothing
about TempData at all, it's a responsibility of a controller. You just
need to copy all necessary data from TempData to ViewData. See
TempDataToViewDataAttribute.cs in MvcContrib project (
http://code.google.com/p/mvccontrib/source/browse/trunk/src/MVCContrib/Filters/TempDataToViewData.cs
) for example.
On Sep 14, 7:52 pm, Chad Lee <chadl...@gmail.com> wrote:
> I noticed that using <viewdata whatever="whatever" /> doesn't work when the
> "whatever" you are trying to retrieve is in TempData. Is this a bug or was
> it designed this way?
>
> If this is by design, I think it would be useful to change the semantics of
> that call to retrieve values from TempData as well as ViewData (with a
> priority on ViewData). Thoughts?