Professional Documents
Culture Documents
NET MVC 3
Buu Nguyen
Buu Nguyen
Microsoft MVP (ASP.NET)
Minor Improvements
Sessionless Controllers ViewBag Property JSON Model Binding Granular Input Validation Partial Page Output Cache Global Action Filters
Technology Stack
NUGET
Contribute at http://nuget.org/Contribute/Index
Basic Syntax
Razor
@exp @(exp) @{ stms; } @Html.Raw(exp) @* cmt *@ @if(cond) { stm; } else { stms; }
ASPX
<%: exp %> <%: exp %> <% stms; %> <%= exp %> <%-- cmt --%> <% if (cond) { stms; } else { stms; } %>
Description Encode and output an expression to the page Explicit expression, e.g. @(imagePath).jpg Execute code statements Output an expression to the page Comment out code block Execute conditional statements Other constructs work the same way: @foreach, @for, @while, @switch, @try etc.
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
Directives
or
Functions
Layout
_ViewStart.cshtml
Code in _ViewStart.cshtml executes before view rendering
Razor Configuration
HTML HELPERS
microsoft-web-helpers
ReCaptcha LinkShare Gravatar
Bing
Analytics FileUpload Video Twitter FaceBook
DEPENDENCY INJECTION
Validation Providers
Model Metadata Providers
IDependencyResolver
Activators
Useful when you dont use an IoC container
MODEL VALIDATION
Model Validation
[Required]
A value must be provided
[Range]
[RegularExpression]
[StringLength]
Value must be a min length and less than the max length
[Compare]
[Remote]
Extensible
MINOR IMPROVEMENTS
Sessionless Controllers
ViewBag Property
Note: all MVC 3 filters are effectively singleton, dont use instance states
HttpStatusCodeResult
RedirectPermanent
RedirectToRoutePermanent RedirectToActionPermanent
Q&A
THANK YOU!
buunguyen@kms-technology.com www.buunguyen.net/blog www.twitter.com/buunguyen http://vn.linkedin.com/in/buunguyen