Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.net mvc Common data for footer

So, I have a footer which will appear on every page of my web application

I need it to render dynamic data so.... this means that every controller action needs to return viewData which contains this data.. as well as the action specific data

How would you guys implement this? The constructor of a base controller perhaps?

like image 904
iasksillyquestions Avatar asked Jan 23 '23 14:01

iasksillyquestions


1 Answers

You're on the right track with the base controller idea, but I would override OnActionExecuted and generate the data there. Check to see if the result is going to be a ViewResult before generating the common data. There's no need to generate the data if the result is a redirect or data going back via AJAX.

You might also consider creating a view-only model for the common data (if the data is extensive) and putting it in ViewData as a whole. Then you can create a strongly-typed partial view that takes the model and use the model's properties more easily in the view. Rendering this partial view from the master page would make it easy to both incorporate the data on every page and use it in a strongly-typed way.

If the footer data or formatting isn't complicated, then just putting the mark up in the master page is probably better.

like image 137
tvanfosson Avatar answered Jan 27 '23 04:01

tvanfosson