Using A Static Class In MVC3

How do I reference a static class in my MVC3 project?

A simple question which actually has a very simple answer, but finding that answer may not be too simple.  In Web Forms we are used to putting these things in the App_Code folder.  Sure you can create one in MVC3 but it doesn’t work like Web Forms.

I remembered a video I watched, probably by John Papa, that mentioned using a Helpers folder.  Sure it was for Silverlight but hey, MVC has helpers too.  So I tried that and it worked!  Now keep in mind that you don’t have to name it Helpers.  Just create a normal folder, give it a meaningful name and stick your stuff in there.  Just like you do with Controllers, Models, and Views.  Also note that you can add a using to the top of the page where you are referencing it (sorry, I’m a C# guy, I’ve not done VB since VB5 or VB6).

About SheldonS

Web developer for over 15 years mainly with Microsoft technologies from classic ASP to .NET 4. Husband, father, and aspiring amateur photographer.

Posted on June 28, 2012, in MVC and tagged . Bookmark the permalink. 1 Comment.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: