I want to set the value of Thread.CurrentCulture
based on some route data, but I can't find an event to hook to that fires after the routes are calculated and before the action method is called.
Any ideas?
ASP.NET MVC Action Methods are responsible to execute requests and generate responses to it. By default, it generates a response in the form of ActionResult. Actions typically have a one-to-one mapping with user interactions.
Action Result is actually a data type. When it is used with action method, it is called return type. As you know, an action is referred to as a method of the controller, the Action Result is the result of action when it executes. In fact, Action Result is a return type.
An action (or action method) is a method on a controller which handles requests. Controllers logically group similar actions together. This aggregation of actions allows common sets of rules, such as routing, caching, and authorization, to be applied collectively. Requests are mapped to actions through routing.
You could write a custom action filter attribute:
public class CustomFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
// This method is executed before calling the action
// and here you have access to the route data:
var foo = filterContext.RouteData.Values["foo"];
// TODO: use the foo route value to perform some action
base.OnActionExecuting(filterContext);
}
}
And then you could decorate your base controller with this custom attribute. And here's a blog post illustrating a sample implementation of such filter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With