Developer Guide
What are Custom Controllers?
    Magentrix allows developers to create special classes that can act as controllers of HTTP requests. When a request is received, Magentrix routes the request to the most suitable controller and maps it to the controller's action as intended by the request. The controller's action can perform any logic and produce a response that is passed back to the Magentrix MVC engine. The response is excuted by Magentrix and the results are transmitted back to the requester.
     
    All ActivePage controllers are derived from AspxController class, which provide all the implementation for several response types such as access to database, request validaton, etc.


    An example of a custom Active Class Controller follows below:

    public class MyPageController : AspxController
    {
         public override ActionResponse Index()    
         {       
           return View();        
         }
    }


    The default action is overridden since it is implemented by the parent AspxController class. Any public method within a controller class is considered an action. You can implement any business logic, perform database operations, pass models to the active pages and much more within an action. Please see "Controller Methods" for more information.

     
    Note: Your controller name must follow a specific format, as shown below:
    Controller Name: {pagename}Controller. 
    Note: The index() action cannot have arguments, as it is dictated by the parent Controller class.

     

    Passing Models to Views from Controllers

    In order to pass a model (object) to a controller, you can instantiate a new class or retrieve a new entity class by reading the database and passing it to the view, as shown below:

    public class MyPageController : AspxController
    {
         public override ActionResponse Index()    
         {
           Contact contact = new Contact { FirstName="Dave", LastName="Mason" };        
           return View(contact);        
         }
    }


    The following Activepage shows how the custom controller above can be used in a page:

    <aspx:aspxpage runat='server' title='My Page'>
      <body>
         <aspx:viewpanel runat='server' title='Contact Details'>
             <aspx:viewsection runat='server' title='Personal Information'>
                  <aspx:inputField runat='server' value='{!Model.FirstName}'/>
             </aspx:viewsection>
         </aspx:viewpanel>
      </body>
    </aspx:aspxpage>


    In the above example, the {!Model.FirstName} is the binding expression that allows the "FirstName" field to be bound to the inputField. InputField in a metadata driven input control that generates the proper representation for a field type specified.