Your SlideShare is downloading. ×
ASP.NET MVC 3
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

ASP.NET MVC 3

18,045

Published on

Slides for my speech at Microsoft Technology Conference in Hanoi, Vietnam, March 2011

Slides for my speech at Microsoft Technology Conference in Hanoi, Vietnam, March 2011

Published in: Technology
0 Comments
9 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
18,045
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
602
Comments
0
Likes
9
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. ASP.NET MVC 3Buu Nguyen
  • 2. Buu Nguyen• Microsoft MVP (ASP.NET)• Vice President of Technology, KMS Technology• Lecturer, RMIT University Vietnam
  • 3. ASP.NET MVC 3 Features Major Improvements Minor Improvements• NuGet • Sessionless Controllers• Razor View Engine • ViewBag Property• HTML Helpers • JSON Model Binding• Dependency Injection • Granular Input Validation• Model Validation • Partial Page Output Cache • Global Action Filters • New Action Result Types
  • 4. ASP.NET MVC OVERVIEW
  • 5. Technology Stack
  • 6. Demo: Travel Log Web App
  • 7. NUGET
  • 8. NuGet - Package Manager for .NET• Available at http://nuget.codeplex.com/
  • 9. Package Manager Console
  • 10. Building NuGet Package• Authoring support • Define dependencies • Transform configuration file and source • Add initialization to web app startup via WebActivator• Contribute at http://nuget.org/Contribute/Index
  • 11. Demo: Combres NuGet Package
  • 12. RAZOR VIEW ENGINE
  • 13. Web Forms vs. Razor
  • 14. Basic SyntaxRazor ASPX Description@exp <%: exp %> Encode and output an expression to the page@(exp) <%: exp %> Explicit expression, e.g. @(imagePath).jpg@{ stms; } <% stms; %> Execute code statements@Html.Raw(exp) <%= exp %> Output an expression to the page@* cmt *@ <%-- cmt --%> Comment out code block@if(cond) { <% Execute conditional statements stm; if (cond) {} else { stms; Other constructs work the same way: @foreach, stms; } else { @for, @while, @switch, @try etc.} stms; } %>
  • 15. Transition to Code• As soon as Razor parser encounters the syntax mentioned in Basic Syntax, it switches to code mode• Escape @ by using @@, e.g. Tweets by @@buunguyen
  • 16. Transition to Markup Option 1: HTML Block Option 2: Text Block Option 3: Single line markup
  • 17. Directivesor
  • 18. Functions
  • 19. Layout
  • 20. _ViewStart.cshtml• Code in _ViewStart.cshtml executes before view rendering• Hierarchical, subfolders override parent folders
  • 21. Razor Configuration
  • 22. Demo: Razor in Travel Log
  • 23. HTML HELPERS
  • 24. Declarative HTML Helpers• Alternative way to write reusable rendering blocks• Can be placed into App_Code folder
  • 25. New HTML Helpers (both declarative & traditional) Built-in microsoft-web-helpers• Chart • ReCaptcha• WebGrid • LinkShare• WebImage • Gravatar • Bing• Crypto • Analytics• WebMail • FileUpload • Video • Twitter • FaceBook
  • 26. Demo: Declarative Helpers in Travel Log
  • 27. DEPENDENCY INJECTION
  • 28. Injecting Dependencies into Controllers
  • 29. DI Points in ASP.NET MVC 3 • registering & injecting controller factories Controllers • injecting controllers • registering & injecting view engines Views • injecting view pages Action Filters • locating & injecting filters Model Binders • registering & injecting Value Providers • registering & injecting Validation Providers • registering & injecting Model Metadata • registering & injecting Providers
  • 30. IDependencyResolver
  • 31. Activators• Useful when you don’t use an IoC container
  • 32. Demo: Dependency Injection in Travel Log
  • 33. MODEL VALIDATION
  • 34. Model Validation [Required] • A value must be provided [Range] • Value must be in a given range e.g. 1-10 [RegularExpression] • Value must satisfy a regular expression [StringLength] • Value must be a min length and less than the max length [Compare] • Value must equal another property e.g. password [Remote] • Value is validated remotely via JSON Extensible… • Custom model validators
  • 35. Other Validation Improvements• Self-validating model with IValidatableObject• ValidationContext for multi-property validation• Client-validation is enabled by default• jQuery Validate plugin is used by default• Unobtrusive client-side validation• EF4 CTP5 works with validation attributes
  • 36. Demo: Remote Validator in Travel Log
  • 37. MINOR IMPROVEMENTS
  • 38. Sessionless Controllers
  • 39. ViewBag PropertyNote: can be used exchangeably with ViewData dictionary
  • 40. JSON Model Binding
  • 41. Granular Input Validation
  • 42. Partial Page Output Cache
  • 43. Global Action FiltersNote: all MVC 3 filters are effectively singleton, don’t use instance states
  • 44. New Action Result Types• HttpNotFoundResult• HttpStatusCodeResult• RedirectPermanent • RedirectToRoutePermanent • RedirectToActionPermanent
  • 45. Demo: Apply to Travel Log
  • 46. Q&A
  • 47. THANK YOU!buunguyen@kms-technology.comwww.buunguyen.net/blogwww.twitter.com/buunguyenhttp://vn.linkedin.com/in/buunguyen

×