Home > Code Generation > MVC-specific CodeRush code declaration providers

MVC-specific CodeRush code declaration providers

September 21st, 2012

There are three code generation providers specific to MVC. They allow you to declare MVC controllers, MVC actions and MVC views correspondingly:

  • Declare Controller
  • Declare Action
  • Declare View

The Declare Controller code provider creates a new MVC controller if one is undeclared. The code provider is available on the corresponding controller name argument of the Action, ActionLink, or RenderAction method invocation, e.g.:

CodeRush Declare Controller Preview

The referenced action is automatically added to the generated controller class:

CodeRush Declare Controller Result

There is also a second version of the code provider which simply calls the Visual Studio built-in dialog for declaring a new controller. You can differentiate between the two code provider by using a special icon over it in the Popup menu.

The Declare Action code provider creates a new MVC action from the reference to an action which is not yet declared. The code provider is available at the corresponding action name argument of the Action, ActionList, or RenderAction method invocation when the appropriate controller from the same method invocation exist:

CodeRush Declare Action Preview

The result will be declared in the appropriate MVC controller:

CodeRush Declare Action Result

The Declare View code provider invokes the Visual Studio built-in Add View code generation feature on the reference to non-existent View:

CodeRush Declare View Preview

Once applied, the Add View dialog appears, where you can specify the required parameters for the new MVC View:

CodeRush Declare View Dialog

Once confirmed, the new MVC view will be added:

CodeRush Declare View Result

Products: CodeRush Pro
Versions: 12.1 and up
VS IDEs: 2008 and up
Updated: Sep/21/2012
ID: C189

Similar Posts: