Controllers Quick Start

In this lesson, we will learn the basics of using controllers for handling GET and POST requests.

In the previous chapters, we learned how to use controllers to build simple responses to HTTP GET requests. These requests are triggered either by clicking a link or by inserting a URL in the browser address bar.

In this lesson, we will learn how to handle form submissions, that is, POST requests, and redirect responses to build a simple application. Further lessons of this chapter will explore in detail the MVC pattern and all controllers’ features.

Invoking action methods with POST

We already know that request URLs are mapped to controller and action method names that are then invoked. In a GET request, parameters passed to action methods are extracted mainly from the URL path and from the query string. In a POST request, we are mainly interested in the names and values of all fields submitted with HTML forms. Moreover, in the case of a form submit we typically use the field values to fill the properties of a complex object more than as separate parameters.

By default, data submitted by a form is sent to the server in the body of a POST request. Moreover, data is encrypted in a format that is completely analogous to the format of query strings. The example below shows a request:

Get hands-on with 1400+ tech skills courses.