Daniil Harik
Daniil Harik

Reputation: 4719

ASP.NET MVC Data access from action attributes

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

Thank You

Upvotes: 0

Views: 227

Answers (1)

John Nelson
John Nelson

Reputation: 5121

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.

Upvotes: 2

Related Questions