Adding a Controller Action

The ASP.NET MVC project creates a default Controller named HomeController. If you want to display a new View in the browser you must add a new method to the Controller as shown in the following code snippet:

public ActionResult MyContact()
        {
            return View();
        }

The name of the method must be same as the View name. This method returns a ViewResult object, which is a type of ActionResult, and contains the processed View to be rendered.

If you want to include a corresponding DataModel to process the View, you must add an Action method as shown in the following code snippet:

public ActionResult MyContact(ContactModel mdl)
       {
            ViewBag.Message = "My Contacts Page.";            
            return View(mdl);
       }

To resolve the DataModel references and make use of the AB Suite Access Layer API you must add the following namespaces in the HomeController:

using ABSuite.AccessLayer.Connector;
using ABSuite.AccessLayer.Connector.Core;
using ABSuite.AccessLayer.Connector.Core.Utility;
 
using Contacts.CF_MVC.DataModels.Models;
using Contacts.CF_MVC.DataModels.Core;

The first three namespaces are used for coding against the AB Suite Access Layer API.

The last two namespaces are used to reference the generated DataModels for a system named Contacts, with a Technology folder named CF_MVC.

You can now run the application and navigate to the URL of the View to display the generated View in the browser. The home page that is displayed first is the default Index.cshtml file that is automatically created by the ASP.NET MVC project.

You can navigate to the new page by entering the path at the end of the URL. The final design of the application should include a button or link that allows you to navigate to the required pages.

The default page generated by Scaffolding creates a set of labels and input fields from the definitions in the DataModel. The name of the attribute in the DataModel is used for the Label text. The fields are arranged in the order as defined in the DataModel. You can rearrange them by updating the Razor View, which is <MVCViewName>.cshtml.

You can also add a button to the page to send the data to the server. For this you must establish a connection with the AB Suite application and add code to perform transactions.