Overview

This Hands-On Lab is based on the Plan My Night demo and uses the following technologies: ASP.NET MVC 2, Visual Studio 2010, .Net Framework 4.0 and ASP.NET Ajax Library Beta. In order to simplify this Lab the original demo solution was reduced in functionality, nevertheless, if you wish to explore the whole demo you can find it in https://msdn.microsoft.com.

ASP.NET MVC is a framework built on top of ASP.NET for creating web applications that use the model-view-controller pattern. Among other features, the ASP.NET MVC framework provides complete control over your HTML Markup, AJAX Integration, Separation of concerns, and Testability. For introductory labs on the MVC Framework, you can refer to https://r.ch9.ms/vs2010b2f.

In this Hands-On Lab, you will go through four new features that have been included in the present release of the MVC Framework.

  • UI Metadata: It is a common problem when creating applications to separate the concerns when rendering views that are tied to an entity. UI Metadata is a set of attributes that can be used to describe how an entity must be rendered. Altogether with the Templated Helpers, the UI Metadata can be used to remove the model-related information from the views, providing an new level of abstraction.
  • Validation: First introduced in ASP.NET Dynamic Data, and now added in ASP.NET MVC 2 Framework, data annotations validation support allows to have the validation logic added through Metadata attributes. Similarly as with UI Metadata, when validating an entity, you have certain data and validation rules that are highly tied to the entity that is being validated. Throughout this lab you will see how to make use of the Metadata Attributes for adding both Server andClient-Side validation.
  • Templated Helpers allow you to automatically associate edit and display elements with the entity being rendered. By doing this, you avoid having to define how data will be rendered in every view. Instead, you define a template, that will be rendered everytime certain data-type is displayed.
  • MVC Areas: It is a common scenario on large web applications having different functionality which have little or no relation at all with the rest of the components and can be grouped or partitioned. MVC Areas provide a way of encapsulating these areas in the form of folders in your project which will then converge into a single web application. Because areas are self contained, this helps managing the complexity when building large web applications since it provides a simplified environment for working with multiple teams.

In this lab, you will begin with an MVC1-like application, and enhance it with these new features while learning the benefits that each one of them provide.

This Hands-On Lab assumes that the developer has basic experience with HTML, JavaScript, the ASP.NET MVC Framework, and the Entity Framework.

Objectives

In this Hands-On Lab, you will learn how to:

  • Make use of the UI Metadata Attributes for reducing the model-related data needed in the views, when rendering entities present in your data model.
  • Add Server and Client-Side Data Annotations Validation to an existing MVC Application.
  • Use Template Helpers for defining how to render specific data-types.
  • Configure and make use of MVC Areas for structuring an MVC Application

System Requirements

You must have the following items to complete this lab:

  • Microsoft Visual Studio 2010
  • Microsoft SQL 2005 or Microsoft SQL 2008 (Express edition or above)
  • ASP.NET MVC 2

Setup

All the requisites for this lab are verified using the Configuration Wizard. To make sure that everything is correctly configured, follow these steps.

Note:
To perform the setup steps you need to run the scripts in a command window with administrator privileges.

  1. Run the Configuration Wizard for the Training Kit if you have not done it previously. To do this, run the CheckDependencies.cmd script located under the Setup folder. Install any pre-requisites that are missing (rescanning if necessary) and complete the wizard.

    Note:
    For convenience, much of the code you will be managing along this lab is available as Visual Studio code snippets. The CheckDependencies.cmd file launches the Visual Studio installer file that installs the code snippets.

Exercises

This Hands-On Lab is comprised by the following exercises:

  1. Exercise 1: UI Rendering Metadata in Asp.Net MVC2
  2. Exercise 2: Client and Server Side Validation in Asp.Net MVC2
  3. Exercise 3: Templated Helpers in Asp.Net MVC2
  4. Exercise 4: Asp.Net MVC Areas

Estimated time to complete this lab: 120 minutes.

Note:
Each exercise is accompanied by an End folder containing the resulting solution you should obtain after completing the exercises. You can use this solution as a guide if you need additional help working through the exercises.

Note:
Each exercise contains a Visual Basic and a C# version; Inside the End/Begin solution folder you will find two folders: VB, containing the Visual Basic version of the exercise, and C#, containing the C# version of it.