Chapter 2. Taking Action in Your Controllers

In this chapter, we will cover:

  • Exposing JSON using a JsonResult with Json.NET
  • Creating custom action result to return an image
  • Constraining an image's size from an ImageResult
  • Creating a CAPTCHA system
  • Generating a PDF order summary
  • Implementing a controller factory for use with StructureMap

Introduction

This chapter is all about the controller—a very important ingredient to the Model View Controller recipe. In this chapter, we will take a look at a few things that can be done with actions and the controllers that host them. We will take a look at some flexibility that is now provided in .NET 4 with optional parameters. Next, we will create a custom action that exposes JSON. After that we will look at how to return image data from an action. With that under our belt, we will implement an action that not only returns an image, but is also able to constrain the sizes of that image. This will be followed by building an image-based CAPTCHA system. Next, we will implement an action that returns a PDF. And lastly, we will take a look at how to implement a controller factory for use with an Inversion of Control (IoC) product, such as StructureMap.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset