Creating Episerver Admin plugins using MVC

It's long past due to forget your webforms skills. As a developer focusing on code management, it's crazy to see that webforms still is commonly used in modern projects. Episerver Admin is made with webforms, but that does not mean your plugins should be dependent on old coding. Here is a simple recipe for how to make Episerver admin tools in MVC.

First of all, you will need to register the route to your plugin(s). This can be done either by adding all routes to different plugins in the same initialization, or do it once per plugin. Find a suitable place to place your InitializableModule. It should look like this:

Registering routes to multiple plugins at once

I prefer doing this once per plugin, and putting the code inside the plugin folder. For small features, it's much easier to maintain the code if everything is at the same place.

Creating all admin tools/plugins as feature folders

Next step is creating the plugin controller. As seen in the folder structure above I usually place this straight below the plugin main folder. Here is an example of how it could look:

Plugin controller

Even though the plugin is being placed in the admin-gui, it can still be reached by non-admins via the GuiPlugIn-url. Therefore you should not forget adding the Authorize-attribute. This restricts who can view and use the plugin. Since it should only be admins using this, CmsAdmins is the role to add. Also remember that the GuiPlugIn url should be the exact same url that you have registered for the plugin in the InitializableModule.

Area = EPiServer.Plugin.PlugInArea.AdminMenu just says that this plugin is being shown in the admin menu. This is the same in webforms and MVC.

As the controller shows, I've also created a ViewModel for the plugin, it's in the same feature folder as the rest of the admin plugin:

Also needed is of course the frontend. Forget the .aspx-es, just create a normal cshtml-file. As you can see in the above screenshots, I do this inside the same plugin-folder, under a View-subfolder.

In admin-mode, you will find your MVC-plugin below the Tools-section here:

So even though Episerver CMS Admin still use webforms, we should forget those webforms skills. Let it be a thing of the past.