You are previewing ASP.NET MVC 2 Cookbook.
O'Reilly logo
ASP.NET MVC 2 Cookbook

Book Description

A fast-paced cookbook with recipes covering all that you wanted to know about developing with ASP.NET MVC

  • Solutions to the most common problems encountered with ASP.NET MVC development

  • Build and maintain large applications with ease using ASP.NET MVC

  • Recipes to enhance the look, feel, and user experience of your web applications

  • Expand your MVC toolbox with an introduction to lots of open source tools

  • Part of Packt's Cookbook series: Each recipe is a carefully organized sequence of instructions to complete the task as efficiently as possible

In Detail

ASP.NET MVC, one of the latest web development platforms from Microsoft, brings the power of MVC programming to ASP.NET development. It simplifies the task of application development and maintenance for developers. However, ASP.NET MVC is filled with so many features that developers end up looking for solutions to the many problems that are encountered in their routine development tasks.

ASP.NET MVC 2 Cookbook will provide solutions for the very specific problems that are encountered while developing applications with the ASP.NET MVC platform. It consists of many recipes containing step-by-step instructions that guide developers to effectively use the wide array of tools and features of ASP.NET MVC platform for web development

ASP.NET MVC Cookbook is a collection of recipes that will help you to perform your routine development tasks with ease using the ASP.NET MVC platform. In this book you will be walked through the solution to several specific web application development problems. Each recipe will walk you through the creation of a web application, setting up any Visual Studio project requirements, adding in any external tools, and finally the programming steps needed to solve the problem. The focus of the book is to describe the solution from start to finish.

The book starts off with recipes that demonstrate how to work effectively with views and controllers – two of the most important ingredients of the ASP.NET MVC framework. It then gradually moves on to cover many advanced routing techniques. Considering the importance of having a consistent structure to the site, the book contains recipes to show how to build a consistent UI and control its look with master pages. It also contains a chapter that is packed with many recipes that demonstrate how to gain control of data within a view. As the book progresses through some exciting recipes on performing complex tasks with forms, you will discover how easy it is to work with forms to jazz up the look of your web site. Building large applications with ease is one of the prime features of the MVC model. Therefore, this book also focuses on tools and features that make building large applications easier to manage. As data plays an important role in the MVC architecture, there are ample recipes dedicated to cover data validation, access, and storage techniques. Finally, the book demonstrates how to enhance the user experience of your visitors by controlling the data at the application, session, caching, and cookie level.

By the end of this book, you will have explored a wide array of tools and features available with the ASP.NET MVC platform

Table of Contents

  1. ASP.NET MVC 2 Cookbook
    1. ASP.NET MVC 2 Cookbook
    2. Credits
    3. About the Authors
    4. About the Reviewers
    5. www.PacktPub.com
        1. Support files, eBooks, discount offers, and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
    6. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Errata
        2. Piracy
        3. Questions
    7. 1. Working with the View
      1. Introduction
      2. Using magic strings and the ViewData dictionary
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      3. Creating a strongly typed view
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      4. Decoupling a strongly typed view with a View model
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      5. Centralizing display logic with templated helpers
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Type-specific templated helpers
          2. Where to put the DisplayTemplates folder?
          3. DataAnnotations on your model to specify UIHints
      6. Using a partial view to segment view code
        1. How to do it...
        2. How it works...
      7. Rendering a child view with Html.RenderAction
        1. How to do it...
        2. How it works...
        3. There's more...
      8. Loading a view template from a database with NVelocity
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Replacing the default MVC view engine with NVelocity
          2. Want to load templates in other ways?
          3. Want to use more than one view engine?
      9. Consuming a JSON with jQuery
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See Also
    8. 2. Taking Action in Your Controllers
      1. Introduction
      2. Exposing JSON using a JsonResult with Json.NET
        1. Getting ready
        2. How to do it...
          1. How it works...
          2. There's more...
          3. See also
      3. A custom ActionResult to return an image
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      4. Specifying the size of an ImageResult
        1. Getting ready
        2. How to do it...
          1. How it works...
          2. There's more...
      5. Creating a CAPTCHA system
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Hatches and colors
          2. What is CAPTCHA?
          3. Other styles of CAPTCHA
      6. Generating a PDF order summary
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      7. Implementing a controller factory for use with StructureMap
        1. Getting ready
        2. How to do it...
        3. How it works...
    9. 3. Routing
      1. Introduction
      2. Creating a route to support a reporting engine
        1. How to do it...
        2. How it works...
      3. Making hackable URLs for a product catalog
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      4. Filter your matches with routing constraints
        1. Getting ready
        2. How to do it...
        3. How it works...
      5. Using wildcard parameters to support slug URLs
        1. How to do it...
        2. How it works...
      6. Creating a 404 page via routing
        1. How to do it...
        2. How it works...
        3. There's more...
      7. Moving routes out of Global.asax
        1. How to do it...
        2. How it works...
        3. There's more...
      8. Supporting pagination in your URLs
        1. How to do it...
        2. How it works...
      9. Supporting content hierarchies with a custom RouteHandler
        1. How to do it...
        2. How it works...
        3. There's more...
      10. Creating a blacklist route constraint
        1. How to do it...
        2. How it works...
    10. 4. Master Pages
      1. Introduction
      2. How to create a master page
        1. How to do it...
        2. How it works...
      3. Determining the master page in the ActionResult
        1. How to do it...
        2. How it works...
      4. Controlling which master page is used with a view base class
        1. How to do it...
        2. How it works...
      5. Setting the master page from a controller base class
        1. How to do it...
        2. How it works...
      6. Passing data to the master page
        1. How to do it...
        2. How it works...
      7. Rendering data in a master page from another view
        1. How to do it...
        2. How it works...
      8. Creating nested master pages
        1. How to do it...
        2. How it works...
    11. 5. Working with Data in the View
      1. Introduction
      2. Reintroducing for and foreach
        1. How to do it...
          1. Initial bits...
          2. foreach over ViewData collection
            1. foreach over strongly typed view model
            2. for over strongly typed view model
        2. How it works...
          1. There's more...
      3. Handling an array of checkboxes
        1. Getting ready
        2. How to do it...
          1. How it works...
          2. There's more...
          3. See also
      4. Handling an array of radio buttons
        1. Getting ready
        2. How to do it...
          1. How it works...
          2. See also
      5. Working with a pageable set of data
        1. Getting ready
        2. How to do it...
          1. How it works...
      6. How to navigate sortable data
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      7. Deleting a record with an intermediary "Are you sure?" page
        1. Getting ready
        2. How to do it...
        3. How it works...
      8. Adding a jQuery delete link with confirmation
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      9. Master/detail page with inline details via jQuery and a partial view
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      10. Creating a master/detail page with modal pop-up and JSON
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
    12. 6. Working with Forms
      1. Introduction
      2. Using HTML helpers to create forms
        1. How to do it...
        2. How it works...
      3. Building a custom HTML helper to display a WYSIWYG
        1. Getting started
        2. How to do it...
        3. How it works...
        4. There's more...
      4. Centralizing create and edit forms for reuse
        1. How to do it...
        2. How it works...
      5. Adding custom attributes to form elements
        1. How to do it...
          1. How it works...
      6. Defining a default button with jQuery
        1. How to do it...
        2. How it works...
      7. Hijaxing a form with jQuery
        1. Getting started
        2. How to do it...
        3. How it works...
      8. Performing an auto post-back with a select list
        1. How to do it...
        2. How it works...
      9. Autocomplete with jQuery UI
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
    13. 7. Simplifying Complex Applications
      1. Introduction
      2. Centralized formatting of common types with templated helpers
        1. Getting ready
        2. How to do it...
        3. How it works...
      3. Making templated helpers for custom types
        1. How to do it...
        2. How it works...
        3. There's more...
      4. Using areas to separate application components
        1. How to do it...
          1. How it works...
          2. There's more...
      5. Creating a "portable area" to use across multiple applications
        1. How to do it...
        2. How it works...
        3. There's more...
      6. Using input builders of MvcContrib
        1. How to do it...
        2. How it works...
      7. Generating forms with Html.InputForm()
        1. How to do it...
        2. How it works...
        3. There's more...
      8. Leaving breadcrumbs for your users with MvcSiteMap
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      9. Displaying tabular data in a grid
        1. How to do it...
        2. How it works...
    14. 8. Validating MVC
      1. Introduction
      2. Basic input validation
        1. How to do it...
        2. How it works...
      3. Data annotations
        1. How to do it...
        2. How it works...
      4. Client-side validation with jQuery
        1. Getting ready
        2. How to do it...
        3. How it works...
      5. Custom validators
        1. How to do it...
        2. How it works...
      6. Remote validation with jQuery
        1. Getting ready
        2. How to do it...
        3. How it works...
    15. 9. Data Access and Storage
      1. Introduction
      2. Mocking your data layer with NBuilder
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      3. Adding support for LINQ to SQL
        1. Getting ready
        2. How to do it...
        3. How it works...
      4. Going old school with ADO.NET
        1. Getting ready
        2. How to do it...
        3. How it works...
      5. XML documents as a data store
        1. Getting ready
        2. How to do it...
        3. How it works...
    16. 10. Application, Session, Cookies, and Caching
      1. Introduction
      2. Keeping track of anonymous visitors versus logged-in users
        1. How to do it...
        2. How it works...
      3. Maintaining a user's information while at your site
        1. How to do it...
        2. How it works...
      4. Remembering a previous visitor
        1. How to do it...
        2. How it works...
      5. Caching your product catalog for faster response times
        1. How to do it...
        2. How it works...
      6. Using output caching to cache an entire page
        1. How to do it...
        2. How it works...
        3. There's more...
      7. Using partial views to cache pieces of a page individually
        1. How to do it...
        2. How it works...
      8. Exposing an application API to your presentation layer
        1. How to do it...
        2. How it works...