Passing data from the page level to block grid ite...
# help-with-umbraco
c
I want to render grid items on my page and I want to pass the results of a search to 2 or more of those grid items. I've done the search in my render controller so that the search is only done once. I have created a ContentModel to store the results of the search. What is the best way for me to make that data available to the block grid items? Has anyone else done this before? How would you go about doing it?
n
I would use TempData or ViewData to pass it through. Otherwise you can look at creating your own custom models for the BlockGrid but then you have loads of views to update
c
Thanks mate, I was just in the middle of testing TempData, will test ViewData too and report back which one works best and why.
Yep, TempData was the perfect choice.
s
Just curious, what is the difference between TempData and ViewData? In our baseline, I've added a ViewData.GetValue(string key) method to fetch things out of ViewData
s
I created a
PageComponentsDto
and pass it to all the blocklist, so each block knows where it is and such like. Quite useful for sharing content, but also making it situationaliy aware of itself (node id, etc)
n
TempData can persist across requests, ViewData get's wiped out on every request I believe
c
actually after looking more into the difference between TempData and ViewData, it seems TempData is designed to not only work between controller and view, but also between controller and controller. ViewData is correct for this. I've just writted a similar extension method to the one you said.
3 Views