views:

200

answers:

1

I have some navigation things that need to hit the database every time a page has been requested. In Rails I would just set an instance variable in the ApplicationController.rb and that would be available to every controller/view.

Now I see that all my controllers inherent from : Controller in .NET MVC. Can I open a partial class for Controller and add an action filter that it would call every time a page is requested?

Or should I create an ApplicationController : Controller, and have all my other controllers inherit from that?

+1  A: 

Controller is an abstract (not partial) class so you'll want to create a base controller class that extends Controller and have your controllers inherit from it. You can find the source code (for RC1 currently) at http://aspnet.codeplex.com/SourceControl/ListDownloadableCommits.aspx. Alternatively you can simply decorate your controllers with an appropriate custom ActionFilterAttribute, though my preference would be the custom base controller unless the filter needs to take parameters that differ for each controller.

tvanfosson