When you build a website in Episerver, a very common requirement will be to call a non-Episerver controller.  Routing within a CMS framework is different than traditional MVC routing.  If you're new to Episerver and you're struggling with your routing, then first, don't sweat it.. it happens to all of us. Next, I suggest you read Episerver Routing For Dummies to get a basic understanding of what's going on behind the scenes.  

For those experienced with Episerver or people with deadlines looming, the summary of the article for those of you who just want to fix your issue is that Episerver does some magic to hook up the correct action and controller on each page request.  A URL on your website links to a page and a page type in an Episever website is created based on a page type, rather than a controller.

On a lot of projects I've worked on, to get normal MVC/partial routing to work correctly, I've usually had to create a specific entry in my routing configuration so the routing works, like so:

On a recent project, someone on the team pointed out that the base controller for both the PageController and the BlockController, both inherit from something called 'ActionControllerBase'.  Doing some Google research it doesn't look like many people have written about ActionControllerBase, so here goes

What Is ActionControllerBase?

ActionControllerBase isn't really anything amazingly special but you may be able to use it on your project when you want to use a standard MVC controller to make your life a little easier. As I mentioned in the introductory blurb, ActionControllerBase is used by the Episerver PageController and BlockController.

The benefit of ActionControllerBase is that it will perform the Episerver magic routing in the background. So, if you need to use a standard MVC controller, instead of having to manually hook up the routing yourself, like in the example above, you can inherit your controller from ActionControllerBase, name your controller and index as normal and in your code and your routing should magically hook up and work.

Creating A Partial Controller

Let's see it in action...

If you use this snippet you should then be able to access your controller using a normal MVC Action call like so and the routing should magically hook-up without you needing to touch your route.config.

If you need to use normal MCV controllers in Episerver and you're having issues with the routing and getting your controller to work, then inherit from ActionControllerBase. Using ActionControllerBase should mean that Episerver sorts out the routing for you and you can use normal MVC calls to access your controllers.