Retrieve data in C# for a list of stores
# help-with-umbraco
t
I have a Document type which holds a list of stores. I need to manipulate some of the data before it is displayed on the view. How could i retrieve the data in C#? I understand i can change the model type in the View but any help in order to get the details in C# would be awesome
r
Hey @TigerMan - for this I would look to use route hijacking and declare a custom controller to manipulate your View Model before passing it onto the view. They have really good examples in the docs - https://docs.umbraco.com/umbraco-cms/reference/routing/custom-controllers
s
Alternatively you could do this via a View component if it's something that is needed on lots of different pages / on your master layout
https://docs.umbraco.com/umbraco-cms/v/12.latest/reference/templating/mvc/viewcomponents Though to get content in the view component you either need to pass in the IPublishedContent model or inject context accessor This guy seems to do (not reviewed the video fully).

https://www.youtube.com/watch?v=AjCzbilCLHI

2 Views