Adding Custom Controllers
Developers can create and configure custom controllers to pass queries to the model and incorporate their own custom methods for calling views based on user input.
After adding the controller to the DSS or DSS Preview solution, add the corresponding views. To test that the custom controller and views function properly, preview or publish a page that uses the schema associated with the view.
Creating a custom controller is beneficial in scenarios where views require custom actions to occur outside the standard functionality of the default controllers. For example, a FormSubmission view might use a custom FormController to handle user-submitted data. If you want to override methods from the default controllers, we recommend creating a custom base controller to maintain a clear distinction between product-provided code and custom code.
To implement a basic custom controller, follow these steps:
Add Custom Controller
Create a basic controller in the DSS or DSS Preview solution, then further customize the controller to suit your needs and preferences.
Add View
Add the view folder and file that will correspond with your new custom controller.
Optional: Enable BaseControllerName App Setting
By default, the DSS and DSS Preview solutions treat CMSPageDefaultController.cs as the base controller, limiting the custom controller to only one view. This means the custom controller name and view folder namemust match in order for the custom controller to correspond with the view. Within the view folder, the views can have different names; they only need to match the corresponding schema names.
However, if you would like more flexibility outside the provided CMS Page Default controller methods, you can enable the BaseControllerName app setting. This setting allows you to specify a different controller as the base controller, giving you the flexibility to run custom code by default for all views within the associated view folder.
Next Steps: After configuring this setting, you can add additional views to the view folder that corresponds with the custom controller.
Test Custom Controller and View
To ensure the custom controller and corresponding views function properly, test them by creating a page schema associated with the view. Use the new schema to create a page and either render the page in the Preview tab or publish the page to the DSS.
If the view file includes the example code from the Add View steps, you will see the
<h1> content on the page.
Task Troubleshooting: If the views do not display as expected, reload
your browser. If loading the view on your DSS, consider clearing the browser
cache. To clear your cache in Google Chrome, press F12 on your keyboard to open the Developer Tools pane, then right-click the Reload button and select Empty
Cache and Hard Reload.
If the views still do not display as
expected, revisit the steps to create the custom controller and corresponding views.
Double-check the following criteria:
- Ensure your solution's NuGet packages are up to date.
- Ensure the naming conventions of the controller, view(s), and schema(s) are consistent and case-sensitive.
- After creating and configuring the custom controller, rebuild the solution.
- Custom controllers can only correspond with one matching view.If multiple view folders correspond with the same controller, the views within those view folders will no longer function properly.
- The controller name and view folder name are always required to share the same name, regardless of whether the BaseControllerName app setting is enabled. The BaseControllerName app setting determines which controller will be loaded by default for all requests. This setting does not affect naming conventions.
- If the BaseControllerName app setting is enabled, the custom controller and view folder name must match.
See CMS 10.6.308–10.6.378: DSS Page Rendering Conflicts Occur If View Corresponds with Multiple Custom Controllers for details.

