Chapter 1 – An Introduction to ASP.NET MVC

This is a rough draft of a chapter from the book ASP.NET MVC Framework Unleashed by Stephen Walther. Comments are welcome and appreciated. When the book is published, the text from this blog entry will be removed and only the code listings will remain.

Order this Book from Amazon

“There is nothing permanent except change.” — Heraclitus

In this chapter, you are provided with an overview and introduction to the Microsoft ASP.NET MVC framework. The goal of this chapter is to explain why you should want to build web applications using ASP.NET MVC.

Because the ASP.NET MVC framework was designed to enable you to write good software applications, the first part of this chapter is devoted to a discussion of the nature of good software. You learn about the software design principles and patterns that enable you to build software that is resilient to change.

Finally, we discuss the architecture of an ASP.NET MVC application and how this architecture enables you to write good software applications. You are provided with an overview of the different parts of an MVC application including Models, Views, and Controllers. You also are introduced to the sample application created when you create a new ASP.NET MVC project.

A Story with a Moral

I still remember the day that my manager came to my office and asked me to build the Single Button Application. He explained that he needed a simple call manager application to help interviewers dial phone numbers while conducting a health survey. The call manager application would load a list of phone numbers and dial each number one-by-one when you hit a button. What could be simpler?

I said, with great earnestness and confidence, that I would have the call manager application done that very same afternoon. I closed my office door, put on my cowboy hat, turned up the music, and pounded out some code. By the end of the day, I had completed the application. My manager was happy and I went home that night with the happy thought that I had done a good day of work.

The next morning, my manager appeared again at my office door. Worried, I asked if there was a problem with the call manager application. He reassured me that the application worked fine. In fact, he liked it so much that he wanted me to add another feature. He wanted the call manager application to display a survey form when a number is dialed. That way, survey answers could be stored in the database.

With heroic determination, I once again spent the day knocking out code. By the end of the day, I had finished updating the call manager and I proudly presented the finished application to my manager.

I won’t continue this story, because anyone who builds software for a living knows how this story ends. The story never ends. Once a software project is brought to life, it is almost impossible to kill it. A software application needs to be continuously fed with new features, bug fixes, and performance enhancements.

Being asked to change software that you have created is a compliment. Only useless software goes stagnant. When people care about software, when software is actively used, it undergoes constant change.

I no longer work at the company where I created the call manager application (I am currently sitting in an office at Microsoft). But, I still have friends at the company and every once in a while I get a report on how the application has changed. Needless to say, it has turned into a massively complex application that supports different time zones, complicated calling rules, and advanced reporting with charts. It can no longer be described as the Single Button Application.

What is Good Software?

I dropped out of graduate school at MIT to launch an Internet startup in the very earliest days of the web. At that time, building a website was very difficult. This was before technologies such as Active Server Pages or ASP.NET existed (we only had stone knives). Being able to save the contents of an HTML form to a database table was a major accomplishment. Blinking text was the height of cool.

When I first started writing software, simply getting the software to do what I wanted was the goal. Adding as many features to a website in the shortest amount of time was the key to survival in the ferociously competitive startup world of the 90’s. I used to sleep in my office under my desk.

During my startup phase, I would define good software like this:

Good software is software that works as you intended.

If I was feeling particularly ambitious, I would worry about performance. And, maybe, just maybe, if I had extra time, I would add a comment or two to my code. But really, at the end of the day, my criterion for success was simply that the software worked.

For the past eight years, I’ve provided training and consulting to large companies and organizations such as Boeing, NASA, Lockheed Martin, and the National Science Foundation. Large organizations are not startups. In a large organization, the focus is not on building software applications as fast as possible; the focus is on building software applications that can be easily maintained over time.

Over the years, my definition of good software has shifted substantially. As I have been faced with the scary prospect of maintaining my own monsters, I’ve changed my definition of good software to this:

Good software is software that works as you intended and that is easy to change.

There are many reasons that software changes over time. Michael Feathers, in his excellent book Working Effectively with Legacy Code offers the following reasons:

1) You might need to add a new feature to existing software

2) You might need to fix a bug in existing software

3) You might need to optimize existing software

4) You might need to improve the design of existing software

For example, you might need to add new a feature to an application. The contact manager application started as a Single Button Application. However, each day, more and more features were added to the application.

You also need to change software when you discover a bug in the software. For instance, in the case of the contact manager, we discovered that it did not calculate daylight savings time correctly (it was waking some people up in the morning!). We rushed to change the broken code.

You also might need to modify a software application to make the application run faster. At one point, the contact manager application took as long as 12 seconds to dial a new phone number. The business rules were getting very complex. We had to rewrite the code to get the phone number retrieval time down to the millisecond range.

Finally, you might need to modify software to improve its design. In other words, you might need to take badly written code and convert it into good code. You might need to make your code more resilient to change.

Avoiding Code Smells

Unless you are careful, a software application very quickly becomes difficult to change. We all have had the experience of inheriting an application that someone else has written and being asked to modify it. Think of the fear that strikes your heart just before you make your first change.

In the game of Pick-up Sticks, you must remove stick after stick from a pile of sticks without disturbing the other sticks. The slightest mistake and the whole pile of sticks might scatter.

Modifying an existing software application is very similar to the game of Pick-up Sticks. You bump the wrong piece of code and you introduce a bug.

Bad software is software that is difficult to change. Robert and Micah Martin describe the markers of bad software as code smells. The following code smells indicate that software is badly written:

· Rigidity – Rigid software is software that requires a cascade of changes when you make a change in one place.

· Fragility – Fragile software is software that breaks in multiple places when you make a change.

· Needless Complexity – Needlessly complex software is software that is overdesigned to handle any possible change.

· Needless Repetition – Needlessly repetitious software contains duplicate code.

· Opacity – Opaque software is difficult to understand.

*** Begin Note ***

These code smells are described by Micah and Robert Martin in their book Agile Principles, Patterns, and Practices in C# on page 104. This book is strongly recommended!

*** End Note ***

Notice that these code smells are all related to change. Each of these code smells are a barrier to change.

Software Design Principles

Software does not have to be badly written. A software application can be designed from the very beginning to survive change.

The best strategy for making software easy to change is to make the components of the application loosely coupled. In a loosely coupled application, you can make a change to one component of an application without making changes to other parts.

Over the years, several principles have emerged for writing good software. These principles enable you to reduce the dependencies between different parts of an application. These software principles have been collected together in the work of Robert Martin (AKA Uncle Bob).

Robert Martin did not invent all of the principles. However, he was the first one to gather the principles into a single list. Here is his list of Software Design Principles:

· SRP – Single Responsibility Principle

· OCP – Open Closed Principle

· LSP – Liskov Substitution Principle

· ISP – Interface Segregation Principle

· DIP – Dependency Inversion Principle

This collection of principles is collectively known by the acronym SOLID (Yes, SOLID is an acronym of acronyms).

For example, according to the Single Responsibility Principle, a class should have one, and only one, reason to change. Here’s a concrete example of how this principle is applied: if you know that you might need to modify your application’s validation logic separately from its data access logic, then you should not mix validation and data access logic in the same class.

*** Begin Note ***

There are other lists of software design principles. For example, the Head First Design Patterns book has a very nice list.

*** End Note ***

Software Design Patterns

Software Design Patterns represent strategies for applying Software Design Principles. In other words, a Software Design Principle is a good idea and a Software Design Pattern is the tool that you use to implement the good idea (It’s the hammer).

The idea behind Software Design Patterns was originally promoted by the book Design Patterns: Elements of Reusable Object-Oriented Software (This book is known as the Gang of Four book). This book has inspired many other books that describe Software Design Patterns.

The Head First Design Pattern book provides a more user-friendly introduction to the design patterns from the Gang of Four book. The Head First Design book devotes chapters to 14 patterns with names like Observer, Façade, Singleton and Adaptor.

Another influential book on Software Design Patterns is Martin Fowler’s book Patterns of Enterprise Application Architecture. This book has a companion website which lists the patterns from the book at:

http://www.martinfowler.com/eaaCatalog/

Software Design Patterns provide you with patterns for making your code more resilient to change. For example, in many places in this book, we’ll be taking advantage of a Software Design Pattern named the Repository Pattern. Eric Evans, in his book Domain-Driven Design, describes the Repository pattern like this:

A REPOSITORY represents all objects of a certain type as a conceptual set (usually emulated). It acts like a collection, except with more elaborate querying capability. Objects of the appropriate type are added and removed, and the machinery behind the REPOSITORY inserts them or deletes them from the database. (see page 151)

According to Evans, one of the major benefits of the Repository pattern is that it enables you to “decouple application and domain design from persistence technology, multiple database strategies, or even multiple data sources.” (ibid) In other words, the Repository pattern enables you to shield your application from changes in how you perform database access.

For example, when we write our forums application at the end of this book, we’ll take advantage of the Repository pattern in order to isolate our forums application from a particular persistence technology. The forums application will be designed in such a way that we could switch between different data access technologies such as LINQ to SQL, the Entity Framework, or even NHibernate.

Writing Unit Tests for Your Code

By taking advantage of Software Design Principles and Patterns, you can build software that is more resilient to change. Software Design Patterns are architectural patterns. They focus on the gross architecture of your application.

If you want to make your applications more change proof on a more granular level, then you can build unit tests for your application. A unit test enables you to verify whether a particular method in your application works as you intend it to work.

There are many benefits that result from writing unit tests for your code:

1) Building tests for your code provides you with a safety net for change.

2) Building tests for your code forces you to write loosely coupled code.

3) Building tests for your code forces you to take a user perspective on the code.

First, unit tests provide you with a safety net for change. This is a point that Michael Feathers emphasizes again and again in his book Working Effectively with Legacy Code. In fact, he defines legacy code as “simply code without tests” (see xvi).

When your application code is covered by unit tests, you can modify the code without the fear that the modifications will break the functionality of your code. Unit tests make your code safe to refactor. If you can refactor, then you can modify your code using Software Design Patterns which results in better code that is more resilient to change.

*** Begin Note ***

Refactoring is the process of modifying code without changing the functionality of the code.

*** End Note ***

Second, writing unit tests for your code forces you to write code in a particular way. Testable code tends to be loosely coupled code. A unit test performs a test on a unit of code in isolation. In order to build your application so that it is testable, you need to build the application in such a way that it has isolatable components.

One class is loosely coupled to a second class when you can change the first class without changing the second class. Test-driven development often forces you to write very loosely coupled code. Loosely coupled code is resistant to change.

Finally, writing unit tests forces you to take a user’s perspective on the code. When writing a unit test, you take on the same perspective as a developer who will use your code in the future. Since writing tests forces you to think about how a developer (perhaps, your future self) will use your code, the code tends to be better designed.

Test Driven Development

In the previous section, we discussed the importance of building unit tests for your code. Test-driven development is a software design methodology that makes unit tests central to the process of writing software applications. When you practice test-driven development, you write tests first and then write code against the tests.

More precisely, when practicing test-driven development, there are three steps that you complete when creating code (Red/ Green/Refactor):

· Write a unit test that fails (Red)

· Write code that passes the unit test (Green)

· Refactor your code (Refactor)

First, you write the unit test. The unit test should express your intention for how you expect your code to behave. When you first create the unit test, the unit test should fail. The test should fail because you have not yet written any application code that satisfies the test.

Next, you write just enough code in order for the unit test to pass. The goal is to write the code in the laziest, sloppiest and fastest possible way. You should not waste time thinking about the architecture of your application. Instead, you should focus on writing the minimal amount of code necessary to satisfy the intention expressed by the unit test.

Finally, after you have written enough code, you can step back and consider the overall architecture of your application. In this step, you rewrite (refactor) your code by taking advantage of software design patterns — such as the Repository pattern — so that your code is more maintainable. You can fearlessly rewrite your code in this step because your code is covered by unit tests.

There are many benefits that result from practicing test-driven development. First, test-driven development forces you to focus on code that actually needs to be written. Because you are constantly focused on just writing enough code to pass a particular test, you are prevented from wandering into the weeds and writing massive amounts of code that you will never use.

Second, a “test first” design methodology forces you to write code from the perspective of how your code will be used. In other words, when practicing test-driven development, you are constantly writing your tests from a user perspective. Therefore, test-driven development can result in cleaner and more understandable APIs.

Finally, test-driven development forces you to write unit tests as part of the normal process of writing an application. As a project deadline approaches, testing is typically the first thing that goes out the window. When practicing test-driven development, on the other hand, you are more likely to be virtuous about writing unit tests because test-driven development makes unit tests central to the process of building an application.

Short Term Pain, Long Term Gain

Building software designed for change requires more upfront effort. Implementing software design principles and patterns takes thought and effort. Writing tests takes time. However, the idea is that the initial effort required to build software the right way will pay huge dividends in the future.

There are two ways to be a developer. You can be a cowboy or you can be a craftsman. A cowboy jumps right in and starts coding. A cowboy can build a software application quickly. The problem with being a cowboy is that software must be maintained over time.

A craftsman is patient. A craftsman builds software carefully by hand. A craftsman is careful to build unit tests that cover all the code in an application. It takes longer for a craftsman to create an application. However, after the application is created, it is easier to fix bugs in the application and add new features to the application.

Most software developers start their programming careers as cowboys. At some point, however, you must hang up your saddle and start building software that will stand the test of time.

What is ASP.NET MVC?

The Microsoft ASP.NET MVC framework is Microsoft’s newest framework for building web applications. The ASP.NET MVC framework was designed from the ground up to make it easier to build good software in the sense of good software discussed in this chapter.

The ASP.NET MVC framework was created to support pattern-based software development. In other words, the framework was designed to make it easier to implement software design principles and patterns when building web applications.

Furthermore, the ASP.NET MVC framework was designed to its core to support unit tests. Web applications written with the ASP.NET MVC framework are highly testable.

The fact that ASP.NET MVC applications are highly testable makes the ASP.NET MVC framework a great framework to use when practicing test-driven development.

ASP.NET MVC is Part of the ASP.NET Framework

Microsoft’s framework for building software applications – any type of application including desktop, web, and console applications – is called the .NET framework. The .NET framework consists of a vast set of classes, tens of thousands of classes, which you can use when building any type of software application. For example, the .NET framework includes classes for working with the file system, accessing a database, using regular expressions, and generating images.

The ASP.NET framework is one part of the .NET framework. The ASP.NET framework is Microsoft’s framework for building web applications. It contains a set of classes that were created specifically to support building web applications. For example, the ASP.NET framework includes classes for implementing web page caching, authentication, and authorization.

Microsoft has two frameworks for building web applications built on top of the ASP.NET framework: ASP.NET Web Forms and ASP.NET MVC (see Figure 1).

Figure 1 – The ASP.NET frameworks

image

ASP.NET MVC is an alternative, but not a replacement, for ASP.NET Web Forms. Some developers will find the style of programming represented by ASP.NET Web Forms more compelling and some developers will find ASP.NET MVC more compelling. Microsoft continues to make heavy investments in both technologies.

*** Begin Note ***

This book is devoted to the topic of ASP.NET MVC. If you want to learn about ASP.NET Web Forms, buy my book ASP.NET Unleashed.

*** End Note ***

The Origins of MVC

The ASP.NET MVC framework is new. However, the MVC software design pattern itself has a long history. The MVC pattern was invented by Trygve Reenskaug while he was a visiting scientist at the Smalltalk group at the famed Xerox Palo Alto Research Center. He wrote his first paper on MVC in 1978. He originally called it the Thing Model View Editor pattern, but he quickly changed the name of the pattern to the Model View Controller pattern.

*** Begin Note ***

Trygve Reenskaug, the inventor of the MVC pattern, is still alive and works as a professor of informatics at the University of Oslo in Norway.

*** End Note **

The MVC pattern was first implemented as part of the Smalltalk-80 class library. It was originally used as an architectural pattern for creating graphical user interfaces (GUIs).

The meaning of MVC shifted radically when the pattern was adapted to work with web applications. In the context of web applications, the MVC pattern is sometimes referred to as the Model 2 MVC pattern.

The MVC pattern has proven to be very successful. Today, the MVC pattern is used by several popular web application frameworks including Ruby on Rails, Merb, and Django. The MVC pattern is also popular in the Java world. In the Java world, MVC is used in the Struts, Spring, and Tapestry frameworks.

The first major MVC framework for ASP.NET was the open source MonoRail project (see CastleProject.org). There continues to be an active developer community around this project.

The Microsoft ASP.NET MVC framework was originally created by Scott Guthrie on an airplane trip to Austin, Texas to speak at the first Alt.NET conference in October, 2007 (Scott Guthrie was one of the co-creators of ASP.NET). Scott Guthrie’s talk generated so much excitement that the ASP.NET MVC framework became an official Microsoft product. ASP.NET MVC 1.0 was released in the first part of 2009.

The Architecture of an ASP.NET MVC Application

An MVC application, a Model View Controller application, is divided into the following three parts:

· Model – An MVC model contains all of an application’s logic that is not contained in a View or Controller. This includes all of an application’s validation logic, business logic, and data access logic. The MVC Model contains model classes which are used to model objects in the application’s domain.

· View – An MVC view contains HTML markup and view logic.

· Controller – An MVC controller contains control-flow logic. An MVC controller interacts with MVC Models and Views to control the flow of application execution.

Enforcing this separation of concerns among Models, Views, and Controllers has proven to be a very useful way of structuring a web application.

First, sharply separating views from the remainder of a web application enables you to redesign the appearance of your application without touching any of the core logic of the application. A web page designer (the person who wears the black beret) can modify the views independently of the software engineers who build the business and data access logic. People with different skills and roles can modify different parts of the application without stepping on each other’s toes.

Furthermore, separating the views from the remainder of your application logic enables you to easily change the view technology in the future. One fine day, you might decide to re-implement the views in your application using Silverlight instead of HTML. If you entangled your view logic with the rest of your application logic then migrating to a new view technology would be difficult.

Separating controller logic from the remainder of your application logic has also proven to be a very useful pattern for building web applications. You often need to modify the way that a user interacts with your application. You don’t want to touch your view logic or model logic when modifying the flow of execution of your application.

Understanding the Sample ASP.NET MVC Application

A good way to get a firmer grasp on the three logical parts of an MVC application is to take a look at the sample application that is created automatically when you create a new ASP.NET MVC project with Visual Studio.

Follow these steps:

1) Launch Visual Studio

2) Select the menu option File, New Project

3) In the New Project dialog, select your favorite programming language (C# or VB.NET) and select the ASP.NET MVC Web Application template. Give your project the name MyFirstMvcApp and click the OK button (see Figure 2).

Figure 2 – Creating a new ASP.NET MVC project

image

Immediately after you click the OK button to create a new ASP.NET MVC project, you’ll see the Create Unit Test Project dialog in Figure 3. Leave the default option selected – Yes, create a unit test project – and click the OK button.

Figure 3 – Creating a unit test project

image

Your computer hard drive will churn for a couple of seconds while Visual Studio creates the default files for a new ASP.NET MVC project. After all the files are created, the Solution Explorer window should contain the files in Figure 4.

Figure 4 – Files in a new ASP.NET MVC project

image

The Solution Explorer window in Figure 4 contains two separate projects: the ASP.NET MVC project and the Test project. The Test project contains all of the unit tests for your application.

ASP.NET MVC Folder Conventions

The ASP.NET MVC framework emphasizes convention over configuration. There are standard locations for each type of file in an ASP.NET MVC project. The ASP.NET MVC application project contains the following folders:

· App_Data – Contains database files. For example, the App_Data folder might contain a local instance of a SQL Server Express database.

· Content – Contains static content such as images and Cascading Style Sheet files.

· Controllers – Contains ASP.NET MVC controller classes.

· Models – Contains ASP.NET MVC model classes.

· Scripts – Contains JavaScript files including the ASP.NET AJAX Library and jQuery.

· Views – Contains ASP.NET MVC views.

When building an ASP.NET MVC application, you should only place controllers in the Controllers folder, JavaScript scripts in the Scripts folder, ASP.NET MVC views in the Views folder, and so on. By following these conventions, you make your application is more easily maintained and it can be more easily understood by others.

Running the Sample ASP.NET MVC Application

When you create a new ASP.NET MVC application, you get a very simple sample application. You can run this sample application by selecting the menu option Debug, Start Debugging (or hit the F5 key).

*** Begin Note ***

When running an ASP.NET MVC application, make sure that the ASP.NET MVC project and not the Test project is selected in the Solution Explorer window.

*** End Note ***

The first time that you run a new ASP.NET MVC application in Visual Studio, you’ll be receive a dialog asking if you want to enable debugging. Simply click the OK button.

When you run the application, your browser opens with the page in Figure 5.

Figure 5 – The sample application

You can use the tabs that appear at the top of the page to navigate to either the Home or the About page. You also can click the Login link to register or login to the application. And, that is pretty much all you can do with the application.

This sample application is implemented with one ASP.NET MVC controller and two ASP.NET MVC views. The sample application does not contain any business or data access logic so it does not contain any ASP.NET MVC model classes.

The controller is located in the Controllers folder:

[C#]

ControllersHomeController.cs

[VB]

ControllersHomeController.vb

If you open the HomeController in the Code Editor window, then you’ll see the file in Listing 1.

Listing 1 – ControllersHomeController.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MyFirstMvcApp.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewData["Message"] = "Welcome to ASP.NET MVC!";

            return View();
        }

        public ActionResult About()
        {
            return View();
        }
    }
}

Listing 1 – ControllersHomeController.vb

<HandleError()> _
Public Class HomeController
    Inherits System.Web.Mvc.Controller

    Function Index() As ActionResult
        ViewData("Message") = "Welcome to ASP.NET MVC!"

        Return View()
    End Function

    Function About() As ActionResult
        Return View()
    End Function
End Class

The file in Listing 1 contains a class with two methods named Index() and About(). Methods exposed by a controller are called actions. Both the Index() and About() actions return a view.

When you first run the sample application, the Index() action is invoked and this action returns the Index view. If you click the About tab, the About() action is invoked and this action returns the About view.

The two views can be found in the Views folder at the following location:

ViewsHomeAbout.aspx

ViewsHomeIndex.aspx

The content of the Index view is contained in Listing 2.

Listing 2 – ViewsHomeIndex.aspx (C#)

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="indexHead" ContentPlaceHolderID="head" runat="server">
    <title>Home Page</title>
</asp:Content>

<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
    <h2><%= Html.Encode(ViewData["Message"]) %></h2>
    <p>
        To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>.
    </p>
</asp:Content>

Listing 2 – ViewsHomeIndex.aspx (VB)

<%@ Page Language="VB" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="indexHead" ContentPlaceHolderID="head" runat="server">
    <title>Home Page</title>
</asp:Content>

<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
    <h2><%= Html.Encode(ViewData("Message")) %></h2>
    <p>
        To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>.
    </p>
</asp:Content>

Notice that a view consists mostly of standard HTML content. For example, the view contains standard <h2> and <p> tags. A view generates a page that is sent to the browser.

Summary

The goal of this chapter was to provide you with an overview of the ASP.NET MVC framework. The first part of this chapter was devoted to a discussion of a definition of good software. You were provided with a brief introduction to software design principles and patterns and the importance of unit tests. You learned how software design principles and patterns and unit tests enable you to create software that is resilient to change.

Next, you were provided with an introduction to the Model View Controller software design pattern. You learned about the history and benefits of this pattern. You learned how the ASP.NET MVC framework implements the Model View Controller pattern and how ASP.NET MVC enables you to perform pattern-based software development.

Finally, we explored the sample ASP.NET MVC application that is created when you create a new ASP.NET MVC project. We took our first look at an ASP.NET MVC controller and an ASP.NET MVC view.

Discussion

  1. Lee Dumond says:

    This is AWESOME. I can’t wait for this book to come out.

    In fact, I recently talked about how excited I am about this upcoming book in a recent blog post: leedumond.com/…/books-i-wish-would-just-come-…

    I hope you consider posting more chapters along the way. August is a long time to wait!

  2. Ryan Rivest says:

    Good stuff! Looking forward to the book Stephen 🙂

  3. Hari says:

    It is really interesting and looking forward for the book…

  4. Diego Guidi says:

    well done, but a mention to monorail could be appreciated 😉

  5. JBS says:

    I understand that this books focus is ASP.NET MVC. I did see that you mentioned ASP.NET MVC is part of ASP.NET and ASP.NET Web Forms is still big investment for ASP.NET group.

    But I think statement “few developers compelled to use ASP.NET MVC and some other might like using ASP.NET Web Forms” – divert people to think that ‘It is purely developer liking’.

    Although I agree that with any technology we can do what we need. Most of the time technology and tools are provided to solve specific practical problems. So it is important that developers understand where to use what OR what tool/technology fits specific scenario better.

    So any pointers on some kind of table/matrix that guides developers – if your requirement is…. to build data centric/Rich web client — then preference is so and so etc details will help.

    Otherwise developers might think ASP.NET MVC is the best way to do everytihng in ASP.NET. At least in current release I don’t believe so.

  6. JBS says:

    To add…

    It helps a lot if you can include more practical examples -using JQuery and AJAX.

    Also it helps to focus on how to build feature rich web portals OR how to include Silverlight content etc.

    If I have many collection of Microsoft and 3rd part ASP.NET Web controls, it is very productive to develop rich web interface for a Intranet world. Many developers [at least me] interested in how to shift to ASP.NET MVC -but don’t lose producvitity.

    There are already lot of examples on how to do simple stuff and not so complex websites based on ASP.NET MVC. It is going to be valuable if you can put focus more on practical issues and real-world development/samples in the book.

    Like someone suggested, it helps if you can at least publish general contents of the book at some point.

    Thanks.

  7. francis says:

    very good!
    hope to add some extra introduce to HtmlHelper and how to create custom complex object such as a gridview..

  8. Andrei Rinea says:

    @JBS : Regarding the productivity, ASP.NET MVC is not much behind WebForms EXCEPT GRIDS. There, as it is today, IT SUCKS. I simply cannot say it differently.

    I mean a sortable, pageable (maybe filterable) grid with GET request (i.e.: no POST(back)) links that don’t need necessarily JavaScript.

  9. sridhar says:

    Thanks stephen..
    it is awesome…
    please describe an example project developed in asp.net mvc ….

    thanks in advance..

  10. Farrio says:

    Great book thanks Stephen 🙂
    Is the code based on RC or Beta or RTM?

  11. You says:

    So you want comments and feedback to improve the quality of your work so that you can make it a good commercial book. And once your book publishes commercially, you’d rather pull this content off instead of leaving a sample around. Sounds very wrong to me, irrespective of any crude agreements you may have with your publisher.

  12. Dan says:

    Found a typo: “you’ll be receive a dialog asking”

  13. Cody Skidmore says:

    Steve,

    I’m a regular reader on your blog. Thanks for the effort. Having tried blogging, I admire your ability to keep posting useful content.

  14. Josh Clark says:

    Great first chapter! Very smooth and readable. I interested in reading the rest when it becomes available. You are off to a great start.

  15. @Diego — Good point 🙂 I added a reference to the MonoRail project in the Origins of MVC section.

    @Fario — The book is based on the RC bits which (fingers crossed) should be almost identical to the RTM bits. ScottGu announced that the ASP.NET RTM is next month.

  16. Porpus says:

    It’s sad that Microsoft has taken this road. By “this road” I mean building new technologies like ASP.NET Ajax and MVC around ASP.NET, and generally focusing on some kind of misguided concept of ROI and pseudo-maintainability over technical excellence.

    I think ASP.NET should die off, except for arenas where it’s necessary, like e-commerce.

    ASP.NET depends on IIS, which is a first class boondoggle. It’s a piece of bloatware that seems to follow the pattern of “mortgage-driven development.” You know how it goes… “you can’t terminate me yet, I haven’t finished initializing my WNDCLASSEX structure! And Visual Studio is trying to debug Javascript… you can’t let me go until it at least repaints its window!”

    MVC seems to resonate with many architects and wannabe architects. And in general, it does seem that many solutions do break down nicely into three projects. Certainly, I would rather open a solution and see three projects than, say, twelve (or just one giant project).

    But ask most of these guys what the M, V, and C are, and you’ll likely get a bunch of generalizations. I had a guy tell me in a job interview once (he was doing the interviewing) that the “model” was “Visual Studio itself!”

    At another job I had a woman from the architecture group tell me that the “BL tier” (which was forced upon us and introduced DCOM, MSMQ, MTS, and God knows what else into otherwise simple apps) should basically include “validation and pass-through of data” and that they typically had a hard time figuring out what to put in BL.

    One anti-pattern I see repeatedly is that developers will attempt to do things using MVC (or N-tier, or three-tier) without realizing that they’ve really just been tasked with writing one tier. So, you end up with a client that purports to be MVC, and a server that purports to be MVC, since everyone wants to be like Microsoft and heaven forbid anyone should be a ‘cowboy’ or a ‘garage hacker.’

    The other prevalent anti-pattern I see is the “chaos plus OO” anti-pattern. The programmer has met all of Microsoft’s (or the GoF’s) knee-jerk standards for proper architecture, but did not have the time or energy left for any other organizational tasks. They have a three-tier app of which they’re quite proud… but don’t ask them to make it run anywhere else, or to resuscitate an old version from source control. I think ASP.NET MVC – as a new system with all sorts of weird dependencies and IDE customizations – must be particularly susceptible to this.

    I have come to expect a bunch of OO hand-waving from MS, which I basically treat as fluff. But I am a bit surprised that they still think ASP.NET is the proper venue for these activities.

    Microsoft used to be the main company that transformed all of the oddball hardware out there from blinking boxes into usable tools. Suppose it’s 1987 and you want to run a flight simulator on the 8-bit Atari your data bought at Woolworth’s; or suppose you want to draw a picture or play a tune on that seemingly boring PC-XT; or even suppose you want to run Unix on something semi-affordable… Microsoft was the answer to these needs and a real savior back then.

    Something has changed… ASP.NET MVC is emblematic for me, and so is the fact that they just fired the whole Flight Simulator team. They should have taken those guys and put them in charge of all the widget-marshallers.

  17. Matt Berseth says:

    Good stuff – really looking forward to the book.

    Matt.

  18. Craig Carns says:

    Stephen first of all good job – I really liked this intro chapter because it did bring a lot of history to logical conclusion for the need of MVC that was clear and understandable. Things that stood out as missing: 1) Put a note in your “Creating a unit test” that it requires VS Pro and is not avaliable in VS Standard. 2) You also assume the “ASP.NET MVC Application Project” type is installed.

  19. @craig — thanks very much for the feedback. These are good changes.

  20. rtpHarry says:

    Porpus mate, are you ok? Do you need a hug?

  21. Craig Carns says:

    Stephen if you need it I would like to volunteer as a book reviewer on any/all chapters (since you liked my previous comments and I am very insterested in this topic). You have my email so contact me if you so choose.

  22. David says:

    LOL – Still wading through your Unleashed 3.5, page 1058 and counting, [which I like alot] and have been playing around with the MVC Beta & RC for the last couple weeks.

    These chapters couldn’t be coming at a better time as I’m putting in a small client site using the RC — keep up the good work.

    @You — Why are you complaining, instead of being thankful? I would think that one gets more out of this methodology than just the finished book at the end — not to mention that it’s free information. Let me guess – your were pissed-off when you got the new bike for Christmas because it was blue instead of red…

  23. yassir says:

    @david — yeah the ASP.NET 3.5 Unleashed is a great book i hope this one will be good too

    @you — as david said this is free stuff and you can (save,print…) this post and keep it for yourself

    @stephen — i see you posted three chapiters so far i liked this one and i hope the other two are good too 😀 and thank you for these posts

  24. Mike Brown says:

    Stephen,
    I love ASP.NET Unleashed, it must have been a labor of love to produce such an all-encompassing tome. From the samples you’ve provided here, the ASP.NET MVC Unleashed book will be a must buy as well.

  25. Hanife says:

    perfect post..!

  26. gerardo1 says:

    necesito instalar esta pagina dentro de mi programa pues tengo dificultades para coorrelo

  27. Nannette says:

    I like your analogy between the cowboy and the craftsman. Many times people come to me with bids that are a fraction of what I know it would cost to create a web application. Mostly from off-shore companies.

    Those I know who go with the fast, cheap bids, get what they pay for. The project is done quickly and cheaply, but the code is crap. The dog and pony hand-off went great, but they spend the next year finding bugs and taking far longer and costing far more than if they had done it right the first time and hired a craftsman.

    And meanwhile, they lose credibility in their market and waste advertising dollars bringing clients to a site that just doesn’t work.

    I also know there are companies out there that charge far more than is necessary for a web application. And a lot of that is due to the vast amount of goofing off on the job. The 20/80 principle. But then, that’s another story.

    Nannette

  28. Nannette says:

    Your content doesn’t tell how to obtain the ASP.NET MVC Web Application Framework or Templates.

    >>3) In the New Project dialog, select your favorite programming language (C# or VB.NET) and select the ASP.NET MVC Web Application template

    For instance, I have Visual Studio 2008, 3.5 framework SP1, and the template is not among my available templates.

    Clicking the link to search online templates brings up no results either.

    These links might be of use:
    http://www.asp.net/MVC/
    http://www.microsoft.com/…/details.aspx

    It is mentioned in your Index.aspx, but…

    Thanks,

    Nannette

  29. Sridhar Sathya says:

    Great book shaping up. Not that I miss the image, but where is Figure 5?

  30. almny says:

    thanks
    it’s really good Introduction

  31. Great Post! Very good introduction is given. Very useful also. Thanks Stephen.

  32. will says:

    usefull script

  33. tr g this is given in attachment. I understand that very well. Thanks.

  34. fire degree says:

    call to extend our car rental, but it ended up being the most memorable part of the trip. I felt weightless, happy, and tired in that way that preludes a wonderfully satisfying night of sleep. I felt like I was on vacation.earn degree &
    online doctoral degree

  35. tutu says:

    サイト買収 is wonderful.
    バーチャルオフィス is wonderful.
    屋形船 is wonderful.
    店舗デザイン is wonderful.
    整体学校 is wonderful.
    お見合いパーティー is wonderful.
    債務整理 is wonderful.
    スパ is wonderful.
    新宿 整体 is wonderful.
    過払い is wonderful.
    マカ is wonderful.
    格安航空券 国内 is wonderful.
    ブライダルエステ is wonderful.
    苗木 is wonderful.
    歌手オーディション is wonderful.
    広島 不動産 is wonderful.
    バイク便 is wonderful.
    ボイストレーニング is wonderful.
    過払い is wonderful.
    バラ is wonderful.
    足やせ is wonderful.
    先物取引 is wonderful.
    洗面化粧台 is wonderful.
    税理士 東京 is wonderful.
    婚活 is wonderful.
    ウェディングドレス is wonderful.
    結婚式 青山 is wonderful.
    薬剤師 募集 is wonderful.
    トイレつまり is wonderful.
    商標更新 is wonderful.
    電話代行 サービス is wonderful.
    ハーレー is wonderful.
    賃貸事務所 東京 is wonderful.
    公会計 is wonderful.
    不動産投資 is wonderful.
    債務整理 東京 is wonderful.
    行政書士 神奈川 is wonderful.
    集中力 アップ is wonderful.
    ディズニーランド is wonderful.
    川越市 不動産 is wonderful.
    川口市 不動産 is wonderful.
    エアコン 工事 is wonderful.
    還暦 お祝い is wonderful.
    プロフィールDVD is wonderful.
    土地活用 is wonderful.
    インプラント 費用 is wonderful.
    ゴルフ会員権 is wonderful.
    さいたま市 不動産 is wonderful.
    子供 習い事 is wonderful.
    永住ビザ
    医療機器 査定

  36. online games says:

    Great book shaping up. Not that I miss the image, but where is Figure 5?

  37. giochi says:

    Very nice and useful tutorial. Thank you
    Puzzle BubbleMahjong

  38. Its a very good post. Thank you

  39. r34 Great Post! Very good introduction is given. Very useful also. Thanks Stephen

  40. r34 Great Post! Very good introduction is given. Very useful also. Thanks Stephen