CTEC2402: Sofware Development Project

Adding Controllers & CRUD Views

One of the biggest advantages of MVC is once a model class has been created and fully annotated, a controller for that class can be added. When the controller is added views for CRUD (Create, Read, Update & Delete) can be automatically added at the same time. Please only add a controller when you are sure that your class has all the fields it needs and all the correct annotation

Adding a Controller

Right click on the Contollers folder and select Add Controller. The controller name must start with the name of the class and end with Controller e.g. CustomerController. Select MVC controller with read/write views. Select the class, e.g. Customer(ProjectName.Models). The very first time you add a controller you will not have a Data Context class so select <New data context> and give it a name such as TalkIsCheapContext. Click Add, and you should have one controller, one context class and four views inside a Views/Customer folder.

Add Controller

The next time you add a controller remember to select the existing Data Context class. If you need to change the base class (Customer) later to add additional fields. You will either have to edit all four views manually, or delete them all and the controller and add them back again to include the extra field(s).