developing ap.net mvc 3
TRANSCRIPT
-
8/13/2019 developing ap.net mvc 3
1/48
ASP.NET MVC 3Buu Nguyen
-
8/13/2019 developing ap.net mvc 3
2/48
Buu Nguyen
Microsoft MVP (ASP.NET)
Vice President of Technology, KMS Technology
Lecturer, RMIT University Vietnam
-
8/13/2019 developing ap.net mvc 3
3/48
ASP.NET MVC 3 Features
Major Improvements
NuGet
Razor View Engine HTML Helpers
Dependency Injection
Model Validation
Minor Improvements
Sessionless Controllers
ViewBag Property JSON Model Binding
Granular Input Validation
Partial Page Output Cache
Global Action Filters
New Action Result Types
-
8/13/2019 developing ap.net mvc 3
4/48
ASP.NET MVC OVERVIEW
-
8/13/2019 developing ap.net mvc 3
5/48
Technology Stack
-
8/13/2019 developing ap.net mvc 3
6/48
-
8/13/2019 developing ap.net mvc 3
7/48
Demo: Travel Log Web App
-
8/13/2019 developing ap.net mvc 3
8/48
NUGET
-
8/13/2019 developing ap.net mvc 3
9/48
NuGet - Package Manager for .NET
Available at http://nuget.codeplex.com/
http://nuget.codeplex.com/http://nuget.codeplex.com/http://nuget.codeplex.com/ -
8/13/2019 developing ap.net mvc 3
10/48
Package Manager Console
-
8/13/2019 developing ap.net mvc 3
11/48
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
http://nuget.org/Contribute/Indexhttp://nuget.org/Contribute/Index -
8/13/2019 developing ap.net mvc 3
12/48
Demo: Combres NuGet Package
-
8/13/2019 developing ap.net mvc 3
13/48
RAZOR VIEW ENGINE
-
8/13/2019 developing ap.net mvc 3
14/48
Web Forms vs. Razor
-
8/13/2019 developing ap.net mvc 3
15/48
Basic Syntax
Razor ASPX Description
@exp Encode and output an expression to the page
@(exp) Explicit expression, e.g. @(imagePath).jpg
@{ stms; } Execute code statements
@Html.Raw(exp) Output an expression to the page
@* cmt *@ Comment out code block
@if(cond) {
stm;
} else {
stms;}
Execute conditional statements
Other constructs work the same way: @foreach,
@for, @while, @switch, @try etc.
-
8/13/2019 developing ap.net mvc 3
16/48
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
-
8/13/2019 developing ap.net mvc 3
17/48
Transition to Markup
Option 3:
Single line markup
Option 1:
HTML Block
Option 2:
Text Block
-
8/13/2019 developing ap.net mvc 3
18/48
Directives
or
-
8/13/2019 developing ap.net mvc 3
19/48
Functions
-
8/13/2019 developing ap.net mvc 3
20/48
Layout
-
8/13/2019 developing ap.net mvc 3
21/48
_ViewStart.cshtml
Code in _ViewStart.cshtml executes before view rendering
Hierarchical, subfolders override parent folders
-
8/13/2019 developing ap.net mvc 3
22/48
Razor Configuration
-
8/13/2019 developing ap.net mvc 3
23/48
Demo: Razor in Travel Log
-
8/13/2019 developing ap.net mvc 3
24/48
HTML HELPERS
-
8/13/2019 developing ap.net mvc 3
25/48
Declarative HTML Helpers
Alternative way to write reusable rendering blocks
Can be placed into App_Code folder
-
8/13/2019 developing ap.net mvc 3
26/48
New HTML Helpers (both declarative & traditional)
Built-in
Chart
WebGrid WebImage
Crypto
WebMail
microsoft-web-helpers
ReCaptcha
LinkShare
Gravatar
Bing
Analytics
FileUpload
Video
Twitter
FaceBook
-
8/13/2019 developing ap.net mvc 3
27/48
Demo: Declarative Helpers in Travel Log
-
8/13/2019 developing ap.net mvc 3
28/48
DEPENDENCY INJECTION
-
8/13/2019 developing ap.net mvc 3
29/48
Injecting Dependencies into Controllers
-
8/13/2019 developing ap.net mvc 3
30/48
registering & injecting controller factories
injecting controllersControllers
registering & injecting view engines
injecting view pagesViews
locating & injecting filtersAction Filters
registering & injectingModel Binders
registering & injecting
Value Providers
registering & injectingValidation Providers
registering & injectingModel Metadata
Providers
DI Points in ASP.NET MVC 3
-
8/13/2019 developing ap.net mvc 3
31/48
IDependencyResolver
-
8/13/2019 developing ap.net mvc 3
32/48
Activators
Useful when you dont use an IoC container
-
8/13/2019 developing ap.net mvc 3
33/48
Demo: Dependency Injection in Travel Log
-
8/13/2019 developing ap.net mvc 3
34/48
MODEL VALIDATION
-
8/13/2019 developing ap.net mvc 3
35/48
Model Validation
A value must be provided[Required]
Value must be in a given range e.g. 1-10[Range]
Value must satisfy a regular expression[RegularExpression]
Value must be a min length and less than the max length[StringLength]
Value must equal another property e.g. password[Compare]
Value is validated remotely via JSON[Remote]
Custom model validatorsExtensible
-
8/13/2019 developing ap.net mvc 3
36/48
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
-
8/13/2019 developing ap.net mvc 3
37/48
Demo: Remote Validator in Travel Log
-
8/13/2019 developing ap.net mvc 3
38/48
MINOR IMPROVEMENTS
-
8/13/2019 developing ap.net mvc 3
39/48
-
8/13/2019 developing ap.net mvc 3
40/48
ViewBag Property
Note: can be used exchangeably with ViewData dictionary
-
8/13/2019 developing ap.net mvc 3
41/48
JSON Model Binding
-
8/13/2019 developing ap.net mvc 3
42/48
Granular Input Validation
-
8/13/2019 developing ap.net mvc 3
43/48
Partial Page Output Cache
-
8/13/2019 developing ap.net mvc 3
44/48
Global Action Filters
Note: all MVC 3 filters are effectively singleton, dont use instance states
-
8/13/2019 developing ap.net mvc 3
45/48
New Action Result Types
HttpNotFoundResult
HttpStatusCodeResult
RedirectPermanent
RedirectToRoutePermanent
RedirectToActionPermanent
-
8/13/2019 developing ap.net mvc 3
46/48
Demo: Apply to Travel Log
-
8/13/2019 developing ap.net mvc 3
47/48
Q&A
-
8/13/2019 developing ap.net mvc 3
48/48
THANK YOU!
[email protected]/blog
www.twitter.com/buunguyen
http://vn.linkedin.com/in/buunguyen