Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any action filters in your project you feel are a must-have?

I'm still not totally clear on why I would need to build custom action filters. Maybe a couple examples would help.

Are there any action filters in your project that you feel are a must-have? Maybe even so important that you re-use them across all your MVC projects?

like image 965
Chaddeus Avatar asked Aug 15 '10 04:08

Chaddeus


People also ask

What are action filters?

Action filters contain logic that is executed before and after a controller action executes. You can use an action filter, for instance, to modify the view data that a controller action returns. Result filters contain logic that is executed before and after a view result is executed.

What step is required to apply a filter globally to every action in your application?

As Global Filter You need to add your filter globally, to add your filter to the global filter. You first need to add it on Global. asax file. You can use FilterConfig.


2 Answers

I use a "Logging" Action Filter to log all calls to my controllers with a dump of the parameters - this can be very useful during third-party testing allowing me to see how/why/when people are interacting with the application.

Although not an Action Filter, I also place a logging hook into my repositories that dumps the SQL generated by any Linq2SQL code ... again useful to see exactly what is being executed and when.

like image 198
JcMaltaDev Avatar answered Sep 23 '22 05:09

JcMaltaDev


My favorite "must have" filter that I use is one that inspects the view model to see if there are any null lists. If there are, it tries to fill them from the database. I primarily use this for populating shared drop down lists so I don't have to put that code in the controller action.

like image 41
Ryan Avatar answered Sep 23 '22 05:09

Ryan