MVC Functions

Using ASP.NET MVC applications as CMS Functions

Important. Before using your ASP.NET MVC applications as CMS Functions in C1 CMS, install the Composite.AspNet.MvcFunctions addon on your website.

To use MVC application as CMS Functions:

  1. Have your MVC application ready.
  2. Copy its files and configuration to the website project.
  3. Register your controllers, actions and define parameters and routes in C1 CMS.
  4. Build and publish the website.

You can now use your MVC functions as regular CMS Functions. You can insert them on pages, make functions calls to them from other CMS Functions, setting parameters in the CMS Console etc.

Let's have a closer look at each step.

Have an MVC application ready

You should have your ASP.NET MVC web application's:

  • output DLL,
  • View folders,
  • and configuration strings

ready.

You can find the configuration strings in your MVC application’s web.config.

Before building the application, make sure that:

  • You build your MVC application with same .NET Framework version as C1 CMS.
  • If you have the <html> tag in your Views, they should have this namespace:
<html xmlns="http://www.w3.org/1999/xhtml">

Copy the MVC application to the website

Once your application is ready:

  1. Copy its DLL to the website project's /Bin folder.
  2. Copy the View folders to the website project’s Views folder.
  3. Copy your configuration strings into the web.config file of the website project.

Register controllers and actions in C1 CMS

After all the required MVC application's files and strings are properly copied to the website project, you should add a class to your website project to:

  • Register your controllers and/or actions
  • Define the parameters and function routes

in the OnBeforeInitiallize method so that the C1 CMS could recognize them as CMS Functions when it initializes.

Please see Registering Functions for more detailed information.

Build and publish the website

Once the class that registers the function has been added to the website project:

  1. Add the reference to the output DLL in the website project
  2. Build and publish your website.

Now you can use the MVC functions on your website.

Requirements

  • ASP.NET MVC 5.2.3 or later