MVC-specific CodeRush code declaration providers
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.:
The referenced action is automatically added to the generated controller class:
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:
The result will be declared in the appropriate MVC controller:
The Declare View code provider invokes the Visual Studio built-in Add View code generation feature on the reference to non-existent View:
Once applied, the Add View dialog appears, where you can specify the required parameters for the new MVC View:
Once confirmed, the new MVC view will be added: