A collection of articles designed to uncover ASP.NET MVC's secrets.

What are Areas? - ASP.NET MVC Demystified

ASP.NET MVC relies on certain conventions (both naming and placement) to properly route requests and return views and view models. One of the ways it allows us programmers to manage these conventions is with the use of Areas, which are modules within an MVC project that exist with their own controllers, views, and actions. Let's learn how we can add Areas to an existing project, and what their separation from the main project allows us to do. What are... Read more >

Using Partial Views - ASP.NET MVC Demystified

When I was writing applications in WebForms (which, thankfully, I no longer do) I often ended up used .ascx files, commonly known as User Controls. Once I moved to MVC, I had to get used to a similar (though not the same) concept: Partial Views. In this tutorial, we'll walk through a use case for Partial Views and explain what they are and why we need to use them. We'll also walk through the two different render methods: @Html.Partial(... Read more >

Attribute Routing vs Convention Routing - ASP.NET MVC Demystified

For most of ASP.NET MVC's lifetime, routing has been accomplished via Convention Routing, which allows developers to specify a format or group of formats which can be used to parse incoming URLs and determine the appropriate actions, controllers, and data to use for that request. In MVC 5, though, Microsoft introduced another scheme called Attribute Routing. Attribute Routing allows us to define routes in close proximity to their actions, giving us greater flexibility. Let's dive into Routing as a... Read more >

What is Unobtrusive Validation? - ASP.NET MVC Demystified

One of the more useful things MVC includes is Unobtrusive Validation with the usage of the jQuery Validate plugin and the Unobtrusive library. This lightweight library allows us to add validation to our MVC views without any additional client-side coding; we only have to use attributes like RequiredAttribute and RangeAttribute and include the correct script files. In this post, we'll take a look at a simple example of how to use Unobtrusive Validation, and break down how it actually works.... Read more >

What is the ActionFilterAttribute? - ASP.NET MVC Demystified

One of the ways MVC allows us to fine-tune what an action does is via the use of Action Filter attributes. Action Filters are attributes which inherit from the ActionFilterAttribute class, and can execute either before or after a decorated action (or before/after every action in a controller) and modify how the action is handled. In this post we'll explore creating a custom Action Filter by inheriting from ActionFilterAttribute. What is an ActionFilter? In ASP.NET, an "Action... Read more >

What is the ModelState? - ASP.NET MVC Demystified

Ever wondered just what the ModelState was that keeps popping up in your ASP.NET MVC controllers? So did I. Let's break down what the ModelState is and why we use it. What is ModelState? ModelState is a property of a Controller, and can be accessed from those classes that inherit from System.Web.Mvc.Controller. The ModelState represents a collection of name and value pairs that were submitted to the server during a POST. It also contains a collection... Read more >