Cartella allows you to define your own Routes and Controllers in the MVC Framework. It does this by implementing its own ControllerFactory

Creating Custom Controllers

There are 2 methods for creating custom controllers. The first is to create a class in the App_Code directory. The other is to create a separate dll and add your class there. If you are going to use the App_Code directory, you can skip the first 2 steps listed below.

  1. Create a Visual Studio Class Library Project

  2. Add references to your project for :

    • System.Mvc

    • Cartella Domain Models

  3. Create your controller class

  4. Derive your class from CartellaViewController

    CopyC#
    using Cartella.Controllers;
    using Cartella.Models;
    using System.Web.Mvc;
    namespace Cartella.CustomControllers
    {
        public class MyCustomController : CartellaViewController
        {
    
        }
    }
  5. Add what ever actions you like. Make sure to return a Cartella view.

    CopyC#
    [CartellaAuthorize]
    public ActionResult MyCustomAction()
    {
        return CartellaView();
    }

Creating Custom Routes

Routes are typically assigned in global.ascx in the Application_Start method. Because you are not able to modify Global.ascx, we have provided an alternative to adding your own routes.

To do this, add a public static method to your controller called "GetCustomRoutes". It must match the following signature exactly.

CopyC#
public static RouteInfo[] GetCustomRoutes()
{
        List<RouteInfo> rts = new List<RouteInfo>();
        //rts.Add(new RouteInfo()
        //{
        //    Name = "",
        //    Url = "",
        //    Defaults = new { },
        //    Contraints = new { }
        //});
        // add as many as you like 
        return rts.ToArray();
}