ASP.NET MVC3 Series

This video series will help you get up to speed quickly with ASP.NET MVC3. The series begins with a demonstration of a canonical application utilizing Razor, Entity Framework Code First, attributes to enable database generation, validation and presentation customizations. After a initial pass at a working application is up and running Bob turns his attention to investigating each individual building block to better understand how each piece is related as well as the many options, plug-ability and extensibility points available.

This series is organized into 5 days’ worth of material:

Jump To …

 

Day 1


ASPNETMVC3_01_01 – Introduction to the Series

This video provides an introduction to ASP.NET MVC 3, the direction and purpose of the series as well as a demonstration of installing Visual Studio 2010 Service Pack 1 to get the proper tools and API’s in place before we begin building a simple CRUD style application in the remainder of Day 1.

ASPNETMVC3_01_02 – ASP.NETMVC3 Project Setup

In this video we’ll take the first steps of walking through a very simple “forms over data” application. The application will allow us to create and modify Customers, Products, Orders with Order Items and so on. It will use ASP.NET MVC3 as a means of exposing our domain model — i.e., the customers, products and orders — to the user via a web-based interface. We’ll use the new Entity Framework Code First feature to start by building our model — simple Plain Old CLR Objects, or rather, POCO classes and allow the Entity Framework Code First to generate the database from our class definitions.

So, this video demonstrates a few startup tasks — some of them are specific to ASP.NET MVC 3 and some are not.

ASPNETMVC3_01_03 – Creating the Domain Model and Generating Code via Scaffolding

The first order of business is to model our domain using C# classes. The Code First feature of the Entity Framework will generate a database from our classes and will rely on some naming conventions we’ll employ to ensure a smooth database generation experience. Once we have our domain model, we’ll then generate controllers and views for these classes using “scaffolding”.

ASPNETMVC3_01_04 – Using Attributes to Enable Authentication and Writing Razor

In this video we demonstrate the utilization of the ASP.NET Authentication and Authorization API in our application. Ideally, we only want certain roles making changes to our Customers and Products, and viewing Orders.

To accomplish this I’ll enable this using attributes on our classes and methods. More importantly, we’ll see how ASP.NET MVC3 utilizes attributes on the model or on the controller to affect how the database is created, whether a particular user should be able to view a web page, form validation and much more.

We’ll also write our first Razor syntax to display a new tab for the Customers list once an Administrator is logged in.

ASPNETMVC3_01_05 – Modifying the Model and Re-Generating the Scaffolding

In this video we begin by reviewing the database table and column structure created automatically by the Entity Framework Code First from our model. Then I post the question, “What happens when we need to make a change to the model? How does that affect the database?” I’ll demonstrate how to initialize the database to re-generate it each time a change is made to the model and discuss the implications for the rest of the scaffolding that was generated from the model as well.

ASPNETMVC3_01_06 – Validation with the Data Annotation Validators

In this video Bob demonstrates the use of attributes on the model classes called “Data Annotations” to enable and configure client and server-side validation, modify whether a column should be generated in the database for a given property, and more.

ASPNETMVC3_01_07 – Seeding the Database with Values when the Model Changes

In this video Bob demonstrates how to take control of the strategy for database initialization to generate seed data in the database each time it is dropped and re-created.

ASPNETMVC3_01_08 – Understanding the Relationship between Controllers and Views

With big changes needed in our example application, Bob explains the relationship to each line of code within the controller’s ActionResult methods and the corresponding Views as well as what gets generated in the HTML as a result of the HTML helper class, the ViewBag, the Model, how model binding works and more.

ASPNETMVC3_01_09 – Modifying the Controller and Views – Part 1

In this first modification, Bob tackles the the controller and view for the Order/Create.

ASPNETMVC3_01_10 – Modifying the Controller and Views – Part 2

In this second modification, Bob tackles the controller and view for Order/Edit to change what can be edited, to view a list of OrderItems associated with the Order, creates a new ActionResult for the GET and POST of the Order/AddItem, create a View using the AddView dialog, modifies the code required to save the changes from the user and navigate back to the Order/Edit page and more.

ASPNETMVC3_01_11 – Modifying the Controller and Views – Part 3

Bob implements the business rules for calculating the OrderTotal and the Tax for a given order through the creation of a service class and integrates it into the Order/AddItem POST route.

 

Day 2


ASPNETMVC3_02_01 – Routing Basics

In a nutshell, the ASP.NET MVC3 engine allows developers to define a collection of Route objects. When a web request is passed from Internet Information Services to the ASP.NET MVC 3 engine, it matches up the URL of the web request with the collection of Route objects. Each Route object defines a rule, or a pattern to match against. Once the pattern has been matched for a given web request URL, the Route object alsdo defined which Controller Class and Action Method the request should be sent to in order to be handled. So, given a URL that looks like this, send it to this class and this method, or in other words, send it to this Controller and this Action.

The collection of route objects is referred to as a Route Map, it’s official name is a RouteCollection and it is configured in the Global.asax because in ASP.NET that is where these big picture types of activities happen. When you create a new ASP.NET MVC3 project, a default route is created — and in the previous videos we just used that route. In the next video we’ll start creating more route objects and will start to experience the power this provides us.

Just to solidify in our minds the connection between Controller Classes, Action Methods and Routes, we’ll experiment with an empty ASP.NET MVC 3 project and ferret out how routing works.

ASPNETMVC3_02_02 – Registering Routes in the Global.asax

In the previous video we looked at how web request URLs are routed to controllers and methods. Continuing our investigation the question arises: Are these mapping route rules ‘hard coded’ or are they in some configurable form? In this video we’ll look at where the routes are configured, how to modify the default configuration and register new routes to customize the route mapping.

ASPNETMVC3_02_03 – Parameter Mapping in Routes

In the previous video we learned that we can modify our route mappings to use part of the URL (i.e., a segment) as input parameters to our Action methods. In this video I dive deep and demonstrate how to accomplish this.

ASPNETMVC3_02_04 – Inspecting the Request and RouteData.Values

In the next three lessons we will talking about how can a Controller Action method can receive input via the URL. We’ll focus on the different types of inputs that our Contoller Actions can inspect solely based on the user’s web request. So our objectives in this lesson: (1) To demonstrate how the Request object allows us to retrieve information about the user’s web request, including the QueryString values. (2) To demonstrate how the RouteData.Values class allows us to get at the route mapping information — so, it’s like the Request object, but AFTER it’s been processed by the pattern match, after the request has been routed to a specific Controller and Action.

ASPNETMVC3_02_05 – Model Binding with Query Strings

In the previous lesson, we’ve seen how to inspect the Querystring to grab key / value pairs and use them in our application. However, with Model binding, we can automate this process and instead of working with just strings, the model binding will both take a collection of key / value pairs AND map them directly to new instances of classes — like custom domain classes or data transfer objects that we create. This video demonstrates a simple example of model binding data sent via the query string to an instance of a custom domain class.

ASPNETMVC3_02_06 – The Basics of Producing Output from Controller Actions

In this lesson we overview the ActionResult class and its derived classes, and talk at length about when to use the more generalized ActionResult versus a more specific version (such as ViewResult, HttpNotFoundResult, etc.) Next, we talk about passing data from the Controller Action method using ViewData and ViewBag.

ASPNETMVC3_02_07 – Creating a Strongly Typed View Model

In the previous lesson we talked about three ways to pass data from the Controller Action methods to the View. The first two methods: ViewData and ViewBag were great for simple scenarios, however there was a downside — they were not strongly typed and therefore were prone to typing mistakes and other inefficiencies. In this lesson we create a class that’s used as a view model and discuss when to use a separate class (and when it’s ok to use an existing data transfer object class or a domain model class for this task).

ASPNETMVC3_02_08 – Razor Syntax Basics – Part 1

In this lesson we’ll talk about the Razor view engine and basic Razor syntax discussing the basics of switching between HTML and C# contexts, implicit expressions, code blocks, escaping the @ symbol, commenting and more.

ASPNETMVC3_02_09 – Razor Syntax Basics – Part 2

In this lesson we’ll keep building our knowledge of the Razor syntax rules and idiosyncrasies with examples of explicit expressions using parenthesis, the element and @: element.


10 Year Anniversary Sale - 30% Off - ENDING SOON!!!    Learn more ...