Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

action filters

$
0
0

Hi, 

i have noticed when using the action filters in mvc 6 the actually context controller definition is an object not of type Controller, i wanted to make sure the following is the correct new way we are now suppose to be using it, below is examples of the original method and the new.

original version method:

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            filterContext.Controller.ViewBag.example = true;            
        }

the new method in mvc 6 method of the same? 

Note: ActionExecutingContext.controller is no longer of type "Controller" but an "Object" in mvc 6

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            ((Controller)filterContext.Controller).ViewBag.example = true;
        }


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>