Asp Netmvc3 110319000548 Phpapp02
Asp Netmvc3 110319000548 Phpapp02
NET MVC 3
Buu Nguyen
Buu Nguyen
Microsoft MVP (ASP.NET)
Vice President of Technology, KMS Technology
Lecturer, RMIT University Vietnam
ASP.NET MVC 3 Features
Major Improvements Minor Improvements
Contribute at http://nuget.org/Contribute/Index
Demo: Combres NuGet Package
RAZOR VIEW ENGINE
Web Forms vs. Razor
Basic Syntax
Razor 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;
}
%>
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
Transition to Markup
Option 1:
HTML Block
Option 2:
Text Block
Option 3:
Single line markup
Directives
or
Functions
Layout
_ViewStart.cshtml
Code in _ViewStart.cshtml executes before view rendering
Hierarchical, subfolders override parent folders
Razor Configuration
Demo: Razor in Travel Log
HTML HELPERS
Declarative HTML Helpers
Alternative way to write reusable rendering blocks
Can be placed into App_Code folder
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
Demo: Declarative Helpers in Travel Log
DEPENDENCY INJECTION
Injecting Dependencies into Controllers
DI Points in ASP.NET MVC 3
registering & injecting controller factories
Controllers injecting controllers
[StringLength] Value must be a min length and less than the max length
Note: all MVC 3 filters are effectively singleton, dont use instance states
New Action Result Types
HttpNotFoundResult
HttpStatusCodeResult
RedirectPermanent
RedirectToRoutePermanent
RedirectToActionPermanent
Demo: Apply to Travel Log
Q&A
THANK YOU!
[email protected]
www.buunguyen.net/blog
www.twitter.com/buunguyen
http://vn.linkedin.com/in/buunguyen