MVC5 Classic
Step 4 of 5: Add Controllers

Next, add controllers for TahDoList and TahDoItem.

  1. In the Solution Explorer, right-click the Controllers folder and select Add | Controller. The Add Controller dialog box opens.
  2. Enter a Controller name, for example, TahDoListController.
  3. Under Template in the Scaffolding options box, select Controller with read/write actions and views, using Entity Framework.
  4. Under Model class, select TahDoList (TahDo.Models), which is the strongly typed class you want a model for.
  5. Under Data context class, select <New data context…>. The New Data Context dialog box opens.

  6. Click OK and then click Add.Visual Studio generates everything you need, including controllers and views for all of the CRUD operations against our model. Links to the Entity Framework for data access have also been automatically created.
  7. You can also add a controller in the same way for a TahDoItemController. Follow steps 1-6 using TahDoItemController for the name and TahDoItem (TahDo.Models) for the Model class.

Now run the project to dynamically create a database and add new items.

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum |  Documentation Feedback