How to set ViewBag properties for all Views without using a base class for Controllers?
The best way is using the ActionFilterAttribute. I’ll show you how to use it in .Net Core and .Net Framework. .Net Core 2.1 & 3.1 public class ViewBagActionFilter : ActionFilterAttribute { public ViewBagActionFilter(IOptions<Settings> settings){ //DI will inject what you need here } public override void OnResultExecuting(ResultExecutingContext context) { // for razor pages if (context.Controller is … Read more