views:

50

answers:

1

Hello,

I was wondering if it's a good/bad practice to access database from ASP.NET MVC action attributes?

Thank You

+2  A: 

Like any good question, it depends.

I think it's probably not a great idea to do it in a filter if you're grabbing large amounts of data. However, getting one or two rows might be fine (even better if your data is cached)

This does have a certain appeal for data that just shows up. For example, using an ActionFilter to get the currently logged in user & store it in ViewData can save you a lot of code.

Final Answer: It's a judgement call.

John Nelson