Chapter 4. Action-packed controllers

 

This chapter covers

  • What makes a controller
  • What belongs in a controller
  • Manually mapping view models
  • Validating user input
  • Using the default unit test project

In the last couple of chapters, we’ve looked at the basics of creating a simple Guest-book application and at different options available for passing data to views. In this chapter, we’ll finish off the Guestbook example by looking at controllers in a bit more detail. We’ll explore what should (and shouldn’t) be part of a controller and look at how to manually construct view models, validate simple user input, and write controller actions that don’t use a view. This will give us a good set of building blocks for constructing the most common types of controller actions.

We’ll also briefly introduce you to unit testing controller actions so you can verify that they’re working correctly. We’ll start off by looking at the default unit test project and then move on to creating unit tests for the GuestbookController that we’ve been working with in previous chapters.

But before we dive into these new concepts, let’s quickly recap the purpose of controllers and actions.

4.1. Exploring controllers and actions

4.2. What should be in an action method?

4.3. Introduction to unit testing

4.4. Summary

sitemap