This particular post is related to utilizing these methods within MVC and the necessary work around for them to work with in your code.
- Create your extension method as normal, and put your Class in a folder you created to house your extensions (typically done in the App_Code folder in ASP.Net web apps - this is not a folder that is an available system folder for MVC)
- Perform a build via the build menu or CTRL+SHIFT+ B
- Attempt to add the Using statement to the top of controller, data model, or class.
Well, this is because in MVC by default the class is added with a build action of "Content". This means that when you build the application it did not compile your extension method class.
So how do you fix this?
This actually extremely easy via the following:
- Right click on the extensions class file you created
- Select Properties
- The first option in properties window is Build Action
- Select Compile from the drop down
- Build the application
*** All Content is provided As Is ***