Adding custom MVC actions

Page controllers can be extended with custom actions. These actions will have the CMS provide the current page to them automatically which can be very useful if you need to use properties that are page specific.

By default the page controller implements an Index action, which is the action that is called when a request for a page URL is made. Like in a standard controller in MVC you can add your custom actions to the page controller. These actions are then routed to as /url/to/page/action/.

If you add a parameter called currentPage to your action of the same page type as your page controller the system will automatically provide you with the page which action was called (in the example URL above it would mean the page responding to /url/to/page/).

The following example shows a custom action that can be called with an optional parameter (like /{a page of the controller's page type}/write/?message=test):

namespace DemoSite.Controllers {
    using KalikoCMS.Mvc.Framework;
    using Models.Pages;
    using System.Web.Mvc;

    public class ArticlePageController : PageController<ArticlePage> {
// Standard page controller action
        public override ActionResult Index(ArticlePage currentPage) {
            return View(currentPage);
        }

// Custom action with optional parameter
        public ActionResult Write(ArticlePage currentPage, string message = "Nothing") {
            return Content("Write: " + message + " (page = '" + currentPage.PageName + "')");
        }
    }
}