ASP net MVC in action

391 7.8K 1
ASP net MVC in action

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Tutorial about MVC steps by steps

MANNING Jeffrey Palermo Ben Scheirman Jimmy Bogard FOREWORD BY PHIL HAACK IN ACTION ASP.NET MVC in Action Licensed to Gayle M. Noll <pedbro@gmail.com> Download at Boykma.Com Licensed to Gayle M. Noll <pedbro@gmail.com> Download at Boykma.Com ASP.NET MVC in Action WITH MVCCONTRIB, NHIBERNATE, AND MORE JEFFREY PALERMO BEN SCHEIRMAN JIMMY BOGARD MANNING Greenwich (74° w. long.) Licensed to Gayle M. Noll <pedbro@gmail.com> Download at Boykma.Com For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. Sound View Court 3B fax: (609) 877-8256 Greenwich, CT 06830 email: orders@manning.com ©2010 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15% recycled and processed without the use of elemental chlorine. Development Editor: Tom Cirtin Copyeditor: Betsey Henkels Manning Publications Co. Proofreader: Elizabeth Martin Sound View Court 3B Typesetter: Gordan Salinovic Greenwich, CT 06830 Cover designer: Leslie Haimes ISBN 978-1-933988-62-7 Printed in the United States of America 1 2 3 4 5 6 7 8 9 10 – MAL – 14 13 12 11 10 09 Licensed to Gayle M. Noll <pedbro@gmail.com> Download at Boykma.Com v brief contents 1 ■ Getting started with the ASP.NET MVC Framework 1 2 ■ The model in depth 24 3 ■ The controller in depth 44 4 ■ The view in depth 65 5 ■ Routing 91 6 ■ Customizing and extending the ASP.NET MVC Framework 119 7 ■ Scaling the architecture for complex sites 152 8 ■ Leveraging existing ASP.NET features 174 9 ■ AJAX in ASP.NET MVC 195 10 ■ Hosting and deployment 216 11 ■ Exploring MonoRail and Ruby on Rails 238 12 ■ Best practices 270 13 ■ Recipes 312 Licensed to Gayle M. Noll <pedbro@gmail.com> Download at Boykma.Com Licensed to Gayle M. Noll <pedbro@gmail.com> Download at Boykma.Com vii contents foreword xiii preface xv acknowledgments xviii about this book xxi about the authors xxvi about the cover illustration xxviii 1 Getting started with the ASP.NET MVC Framework 1 1.1 Picking apart the default application 3 Creating the project 4 ■ Your first routes 7 ■ Running with the starter project 9 1.2 Your first ASP.NET MVC controller from scratch 14 1.3 Our first view 16 1.4 Ensuring the application is maintainable 18 1.5 Testing controller classes 20 1.6 Summary 22 2 The model in depth 24 2.1 Understanding the basics of domain-driven design 25 2.2 Domain model for this book 26 Key entities and value objects 26 ■ Aggregates 27 ■ Persistence for the domain model 29 Licensed to Gayle M. Noll <pedbro@gmail.com> Download at Boykma.Com CONTENTS viii 2.3 Presentation model 31 Presentation model responsibilities 31 ■ Projecting from the domain model 33 2.4 Working with the model 34 Crafting the route 35 ■ Crafting the controller action 35 ■ Test- driving the feature 36 ■ Finishing the view 39 2.5 Summary 42 3 The controller in depth 44 3.1 The controller action 45 3.2 Simple controllers do not need a view 47 3.3 Testing controllers 50 Testing the RedirectController 50 ■ Making dependencies explicit 52 ■ Using test doubles, such as stubs and mocks 53 ■ Elements of a good controller unit test 55 3.4 Simple actions and views 56 3.5 Working with form values 57 3.6 Processing querystring parameters 58 3.7 Binding more complex objects in action parameters 59 3.8 Options for passing ViewData 61 3.9 Filters 62 3.10 Summary 64 4 The view in depth 65 4.1 How ASP.NET MVC views differ from Web Forms 66 4.2 Folder structure and view basics 67 4.3 Overview of view basics 69 Examining the IViewEngine abstraction 70 ■ Understanding master pages in the ASP.NET MVC Framework 71 ■ Using ViewData to send objects to a view 73 ■ Partial views can help decompose a complex screen 76 4.4 Leveraging the view to create dynamic screens 79 Rendering forms with view helpers and data binding 79 ■ Posting HTML forms back to the server 84 ■ Validation and error reporting 85 ■ Extending HtmlHelper 88 4.5 Summary 90 Licensed to Gayle M. Noll <pedbro@gmail.com> Download at Boykma.Com CONTENTS ix 5 Routing 91 5.1 What are routes? 92 What’s that curl command? 92 ■ Taking back control of the URL with routing 94 5.2 Designing a URL schema 95 Make simple, clean URLs 95 ■ Make hackable URLs 96 ■ Allow URL parameters to clash 96 ■ Keep URLs short 97 ■ Avoid exposing database IDs wherever possible 97 Consider adding unnecessary information 98 5.3 Implementing routes in ASP.NET MVC 99 URL schema for an online store 102 ■ Adding a custom static route 103 ■ Adding a custom dynamic route 103 ■ Catch-all routes 105 5.4 Using the routing system to generate URLs 107 5.5 Creating routes for Code Camp Server 108 5.6 Testing route behavior 111 5.7 Using routing with existing ASP.NET projects 115 5.8 Summary 117 6 Customizing and extending the ASP.NET MVC Framework 119 6.1 Extending URL routing 120 6.2 Creating your own ControllerFactory 125 The ControllerFactory implementation 126 ■ Leveraging IoC for your controllers 130 6.3 Extending the controller 134 Creating a FormattableController 135 ■ Working with action filters 138 6.4 Creating a custom view engine 141 6.5 Customizing Visual Studio for ASP.NET MVC 145 Creating custom T4 templates 145 ■ Adding a custom test project template to the new project wizard 148 6.6 Summary 150 7 Scaling the architecture for complex sites 152 7.1 Taming large controller actions 153 7.2 Whipping views into shape 156 Using and creating view helpers 156 ■ Creating partials 159 ■ Creating components 163 Licensed to Gayle M. Noll <pedbro@gmail.com> Download at Boykma.Com [...]... share in his passion for building web applications Keep in mind that this book is not only an invitation to learn about ASP. NET MVC, but also an invitation to join in the community and influence the future of ASP. NET MVC Happy coding! PHIL HAACK SENIOR PROGRAM MANAGER ASP. NET MVC TEAM MICROSOFT Download at Boykma.Com Licensed to Gayle M Noll preface My career started in the mid-nineties... separate it from ordinary text Code annotations accompany many of the listings, highlighting important concepts In some cases, numbered bullets link to explanations that follow the listing The source code for the examples in this book is available online from the publisher’s website at http://www.manning.com /ASP. NETMVCinAction Author Online The purchase of ASP. NET MVC in Action includes free access... and I launched the MvcContrib open-source project with an initial offering of extensions that integrated with the ASP. NET MVC Framework At the time of publishing this book, the ASP. NET MVC framework is a frequently used tool at Headspring Systems, where I facilitate the consulting practice For the NET industry as a whole, I predict that ASP. NET MVC will be considered the norm for ASP. NET development by... some of the older books covering the ASP. NET pipeline and server runtime Because ASP. NET MVC layers on to ASP. NET, it is important to understand the fundamentals If you are a current ASP. NET developer, you will find that this book does not insult your intelligence It is a fastpaced book aimed at giving you the why and not just the how Since ASP. NET MVC is a new technology offering you can expect several... management Caching 179 storage 184 8.3 179 Session state Tracing and debugging TraceContext 8.4 ■ 186 ■ 183 Cookies ■ 9 ■ Request 185 Health monitoring 186 Implementing personalization and localization 187 Leveraging ASP. NET personalization ASP. NET localization 188 8.5 8.6 184 187 Implementing ASP. NET site maps Summary 194 ■ Leveraging 192 AJAX in ASP. NET MVC 195 9.1 9.2 9.3 Diving into AJAX with an... ASP. NET The platform has proven itself in the marketplace, and when combined with IIS running on Windows, ASP. NET can easily support complex web applications running in large data centers The ASP. NET MVC Framework leverages the success of ASP. NET and Web Forms to propel ASP. NET forward as a leader in the web application development space The ASP. NET MVC Framework has been introduced to simplify the complex... Web Developer 2008 SP1, NET 3.5 SP1, and the ASP. NET MVC Framework installed to proceed The MVC framework is an independent release that builds upon NET 3.5 Service Pack 1 The examples in this book will use Visual Studio 2008 SP1, but you can find information on using the free Visual Web Developer Express 2008 SP1 on the ASP. NET MVC website: http:// www .asp. net/ mvc/ We’ll begin in Visual Studio 2008... been introduced to simplify the complex parts of Web Forms application development while retaining the power and flexibility of the ASP. NET pipeline The ASP. NET infrastructure and request pipeline, introduced in NET 1.0, stay the same, and ASP. NET MVC provides support for developing ASP. NET applications using the Model-View-Controller web presentation pattern The concerns of the data model, the application... covers both The chapter explores working with form values and querystring values, and it covers model binding, which is one of the most-needed abstractions for ASP. NET to date Chapter 3 concludes after outlining all the available extension points that are built in Chapter 4 gives further insight into views After outlining the key abstractions in the default view engine, it pulls the reader along to essential... with ASP. NET MVC was difficult Jeffrey Palermo, the lead author of ASP. NET MVC in Action, was among the most vocal in providing feedback during this time We took this feedback and implemented a major API change by introducing the concept of action results, which was a much better design than we had before Community involvement helped us build a better product ASP. NET MVC focuses on solid principles . 194 9 AJAX in ASP. NET MVC 195 9.1 Diving into AJAX with an example 196 9.2 AJAX with ASP. NET Web Forms 198 9.3 AJAX in ASP. NET MVC 200 Hijaxing Code Camp. of view basics 69 Examining the IViewEngine abstraction 70 ■ Understanding master pages in the ASP. NET MVC Framework 71 ■ Using ViewData to send

Ngày đăng: 02/03/2014, 19:05

Từ khóa liên quan

Mục lục

  • Front cover

  • brief contents

  • contents

  • foreword

  • preface

  • acknowledgments

    • Jeffrey Palermo

    • Ben Scheirman

    • Jimmy Bogard

    • about this book

      • Who should read this book?

      • Roadmap

      • Code conventions and downloads

      • Author Online

      • about the authors

        • About the technical reviewers

        • about the cover illustration

        • Getting started with the ASP.NET MVC Framework

          • 1.1 Picking apart the default application

            • 1.1.1 Creating the project

            • 1.1.2 Your first routes

            • 1.1.3 Running with the starter project

            • 1.2 Your first ASP.NET MVC controller from scratch

            • 1.3 Our first view

            • 1.4 Ensuring the application is maintainable

Tài liệu cùng người dùng

Tài liệu liên quan