Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC
IT SOLUTIONS, SERVICES, & PRODUCTS TECHNOLOGIES Microsoft, Oracle, IBM, Open Source Integration, Application Performance Management, Security TrainingManaged Services Infrastructure Engineering Application Development Enterprise Content Management BUSINESS INTEGRATION SERVICES IT departments Business departments CUSTOMER Business Intelligence Trivadis solutions portfolio and competences
Hamburg Düsseldorf Frankfurt Stuttgart Munich Freiburg Vienna Basel Bern Zurich Lausanne ~370 employees ~170 employees ~20 employees Trivadis facts & figures 11 Trivadis locations with more than 550 employees Financially independent and sustainably profitable Key figures 2010 Revenue CHF 101 / EUR 73 mio. Services for more than 700 clients in over 1‘800 projects Over 170 Service Level Agreements More than 5'000 training participants Research and development budget: CHF 5.0 / EUR 3.6 mio.
Agenda What is ASP.NET MVC Building a Website Features we need to know
What is ASP.NET MVC Web Development Framework Based on the ASP.NET Framework Based on the MVC Design Pattern Acronym for Model ● View ● Controller Separation of concerns
ASP.NET Web Forms ASP.NET MVC ASP.NET Framework.NET Framework
Technologie Focus ASP.NET WebForms Make Web Development fast and easy Hide Web Specifica WinForms similar Programming Model Statefull, event driven, many rich controls ASP.NET WebForms Make Web Development fast and easy Hide Web Specifica WinForms similar Programming Model Statefull, event driven, many rich controls ASP.NET MVC Full Control Web Development Great Testability, Maintainability and Extensibility Stateless, trendy, separation of concerns, perfect ajax integration ASP.NET MVC Full Control Web Development Great Testability, Maintainability and Extensibility Stateless, trendy, separation of concerns, perfect ajax integration
Agenda What is ASP.NET MVC Building a Website Features we need to know
Build a website in 5 steps AdventureWorks DB CRUD Functionality for Vendor table
Setup the Solution
Model Business Logic Layer Data Access Layer Architecture Repository Pattern Services Layer This is not ASP.NET MVC specific Model
Demo Architecture MVC Project Controller View Model Data Project Entity Framework Model DataAnnotations Services Project IEn…on GetItems(); T GetItem(int id); void Save(); IEn…on GetItems(); T GetItem(int id); void Save(); IRepository IEnumeration GetItems(); T GetItem(int id); void Save(); IEnumeration GetItems(); T GetItem(int id); void Save(); VendorRepository Model
Define the Model
Controller Class in C# (VB) Handles all interactions and requests Controller base class Provides many helper methods Action Return Values For testing purpose Controller
Build the Controller
View Aspx or Razor (.cshtml) File No Code Behind File Controls No Server Controls (no ViewState) Pure HTML Code Presentation Logic in C# (VB) or JavaScript Html Helper class Views
Build some Views
Test Controller Logic Seperate Test Projects Views Models Usefull tools Dependency Injection (DI) Mock Framework Unit Test
Build a Unit Test
Agenda What is ASP.NET MVC Building a Website Features we need to know
Validation Supports DataAnnotations Features Attributes on the model Generates Client- and Server Code.NET 4 DA-Features Support (Version 3 Feature) IsValid overloads in the ValidationAttribute IValidatableObject Interface Remote Validation Attribute (Version 3 Feature) Defines Controller and Action for jQuery validation
Filters Aspect Oriented Programming (AOP) Framework Integrated in ASP.NET MVC Standard Filters [HandleError], [Authorize], [OutputCache] Base class for your own filter Global Filters (Version 3 Feature) Conditional filters thru IFilterProvider
Compact, Expressive and Fluid Easy to learn Is not a new language Works with any Text Editor Visual Studio provides Intellisense and syntax highlighting
1 character instead of 5 for code blocks (no closing tag needed) Parser has semantic knowledge of C# / VB Aspx: Coding is fast, fluid and fun
“Hello world” sample " %> Razor Demo Razor Demo Hello World, we got Number 1: and Number = "Razor Demo";} Razor Demo Hello World, we got Number and Number Razor aspx
Trivadis TechDays11 Wettbewerb
© 2011 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.