Sample chapter from ASP.NET MVC 1.0 Quickly

Edit on GitHub

image Here’s a shameless, commercial blogpost… With yesterday’s 1.0 release of the ASP.NET MVC framework, I’m sure the following sample chapter from my book ASP.NET MVC 1.0 Quickly will be of use for people starting ASP.NET MVC development: Your first ASP.NET MVC application.

When downloading and installing the ASP.NET MVC framework SDK, a new project template is installed in Visual Studio. This chapter describes how to use the ASP.NET MVC project template that is installed in Visual Studio. All ASP.NET MVC aspects are touched briefly by creating a new ASP.NET MVC web application based on this Visual Studio template. Besides view, controller, and model, new concepts including ViewData—a means of transferring data between controller and view, routing—the link between a web browser URL and a specific action method inside a controller, and unit testing of a controller are also illustrated here.

In this chapter, you will:

  • Have an overview of all the aspects of an ASP.NET MVC web application
  • Explore the ASP.NET MVC web application project template that is installed in Visual Studio 2008
  • Create a first action method and corresponding view
  • Create a strong-typed view
  • Learn how a controller action method can pass strong-typed ViewData to the view
  • Learn what unit testing is all about, and why it should be used
  • Learn how to create a unit test for an action method by using Visual Studio's unit test generation wizard and modifying the unit test code by hand

Download the free sample chapter here. Or order the full book, here. That’s a better option ;-)

By the way, if you are interested in the book writing process itself, check my previous blog post on that.

kick it on DotNetKicks.com

This is an imported post. It was imported from my old blog using an automated tool and may contain formatting errors and/or broken images.

Leave a Comment

avatar

6 responses

  1. Avatar for Bill Beckelman
    Bill Beckelman March 19th, 2009

    Maarten,

    I purchased the book yesterday and look forward to digging into it over the weekend.

    Bill

  2. Avatar for maartenba
    maartenba March 19th, 2009

    Cool, thanks! Do let me know if you have any comments on it.

  3. Avatar for Vladimir Kelman
    Vladimir Kelman April 12th, 2009

    Hello!
    I'd like to apologize for novice and possible stupid question... I started to read your book and to play with examples and run Chapter 3 / Updating Data Example. Its Index.aspx View uses Html.ActionLink() methods to produce links, like
    <%=Html.ActionLink("Request variables", "Edit", new { id = 0, postAction = "RequestVariables", formName = "HelperForm" })%>
    When I run application this renders the following link:
    http://localhost:2438/Home/Edit/0?postAction=RequestVariables&formName=HelperForm

    MSDN says (http://msdn.microsoft.com/e... about last parameter of ActionLink() method:
    routeValues: "An object that contains the parameters for a route..."

    So, how does ActionLink() know to render "id" parameter differently from "postAction" and "formName" parameters?
    I see that "id" becomes a part of URL which corresponds to {id} part of the route, while "postAction" and "formName" become part of query string. Is "id" some kind of magic string?
    I tried to replace "id" with "id1" on Index.aspx which immediately leads to producing UR like
    http://localhost:2438/Home/Edit/?id1=0&postAction=RequestVariables&formName=HelperForm

  4. Avatar for maartenba
    maartenba April 14th, 2009

    Hello Vladimir,

    The routing engine actually "sees" that there is a route that expects the id parameter. ActionLink() uses the route dictionary to determine the URL, which will thus be generated using the id parameter from the route. Parameters that are not in the route are appended as a query string.

    Regards,
    Maarten

  5. Avatar for Vladimir Kelman
    Vladimir Kelman May 12th, 2009

    Got it, thank you. I replaced id to id1 in global.aspx.cs for a moment, and index.aspx immediately started to render id as a query string, since id was no more in the route.

    Maarten, is there something like a forum (perhaps a Google Group) for readers of your book? I don't really want to bother you with questions, on which many readers, more knowledgeable than me, could answer. And... it just helps to have a group of people who share similar learning goal. I know it well by "Authors forums" for Manning books.

  6. Avatar for maartenba
    maartenba May 12th, 2009

    Only thing I am aware of is this one: http://www.packtpub.com/con...