Jan 11, 2016
Ori Calvo, 2010Hi-Tech College
“If people want to have maximum reach across *all* devices then HTML will provide the broadest reach”
Scott Guthrie, Corporate Vice President, Microsoft
ObjectivesASP.NET MVC BasicsWhat’s new in ASP.NET MVC 3Summary
PrerequisitesASP.NET DeveloperGood understanding of HTML and HTTPGood understanding of C# 3.0 LanguageNo ASP.NET MVC Experience is required
Quick DemoCreate new ASP.NET MVC ProjectCreate new controllerCreate new View
Classical ASP.NETHuge shift at that timeObject oriented approachCompiled web pagesStateful UIEvent DrivenDrag and Drop DesignerWindows Forms Developing ExperienceIs here to stay !!!
What’s wrong with it?Is “Windows Forms” approach suited?Limited control over HTMLEncourages mixing of presentation and logicHard to testViewStateComplex page life cycleHard to integrate with other libraries
ASP.NET MVCSeparation of concernsTight control over HTMLDesigned to be testableExtensible routing systemBetter integration with 3rd party librariesOpen sourceBuilt on top of ASP.NET platformLanguage innovations
Software Requirements.NET Framework 4.0Visual Studio 2010Visual Web Developer 2010Can be installed into the bin directory
In case the Web Host does not support it directly
Installation can be automated by Web Platform Installer
Additional components can be installed using NuGet
Web Platform Installer
MVC IngredientsRouting SystemControllerActionFilterViewModelModel StateView Bag
Demo – Real life controllerGroupControllerIndex ViewClick a groupBack to parent
Demo – Extending ViewsPartial View - MenuLayouts - Header and footerSections – Add “scripts” section
Demo – Submitting DataCreate new groupMethod selectorAutomatic model bindingValidationDataAnnotationsEdit a groupTryUpdateModeljQuery to set focus
Demo – Controlling AccessAuthorize filterFormsAuthenticationLoginDetails as ViewModel
Demo – Routing SystemSimplifying URLsImplement “CMS like” URLs
What’s new?ASP.NET MVC 3NuGet 1.1IIS Express 7.5SQL Server Compact Edition 4.0Web Deploy and Web Farm Framework 2.0Orchard 1.0Web Matrix 1.0Entity Framework Code First (CTP5)
RazorJust another View EngineBetter integration of C# and HTMLIs focused around the @ characterNo need to set the end of codeIs testableIs extendibleFollows the same compilation model as ASPXCan be compiled at design time
Razor syntaxUse @ to move between code and HTMLUse @() to specify long expressionUse @{} to run arbitrary code which doesn’t
writes into the response streamUse @: inside code region to move back to
HTMLCan also use <text>
Use @* and *@ for commentsUse @functions to add some functionsUse @inherits to specify different base class
Demo - RazorResolve ambiguitiesCreate a unit testWrite inline template
NuGetConsider following scenario
You want to install a library named XX has a dependency on Y You also want to install library named ZZ has a dependency on Y
Need to think about:Where can you get latest of all libraries?What are the dependencies of each library?Is it ok to use the latest release for Y?If not, what happens if Z depends on a different
version of Y than X?
NuGetA library package managerDeals with packages rather than assembliesAn extension to Visual Studio 2010Not just for ASP.NET MVC projectsPackages come from a well known repositoryAutomatically handling of version conflicts and
updatesOnce package is imported NuGet stays out of
the wayNo integration with TFS
NuGet AlgorithmNever installs assemblies at machine levelUses bin deployPrefers unification over “side by side”Always picks the lowest version of a
dependency that fits in the range Always move up to the highest build/revisionCan use the Add-BindingRedirect power shell
command
Demo - NuGetInstall T4MVCInstall NHibernateHandle conflictsGet a list of updates availableCreate a local repositoryGive a look at http://nuget.org
IIS ExpressQuick installation (less than 10MB)Better support for IIS feature set
SSLIntegrated ModeURL Re-WritingSame configuration schema
Does not require administrator privilegesDoesn’t run as a serviceCan co-exist with full IIS7.x and CassiniWorks on Windows XP SP3 and laterSupports multiple users on the same machineSupports WCF but only over HTTPIntegrated into Visual Studio 2010 SP1 beta
Demo - IIS ExpressChanging VS to work with IIS ExpressChange VS defaultExecute under Integrated ModeChange application pool using AppCmd.exe
Demo – EF Code FirstUse DbContextChange the database nameUse SQL CEDispose the contextUse validation
What’s new in ASP.NET MVC 3?Unobtrusive JavaScriptPosting JSON objectsClass level model validationPartial page output cachingBetter Dependency InjectionViewBagGlobal FiltersSessionless Controller
ASP.NET MVC vs. ASP.NET Web FormsBoth based on ASP.NET infrastructureSame objectives, different waysBoth server centricHow sophisticated the UI need to be?Are you planning for automation coverage?What is your team developing background?Can mix both in the same projectYou can use ASP.NET Server Controls inside
views (don’t tell anybody …)
SummaryA different way to develop web applicationsRazor Syntax – Clear & easier to maintainNuGet – Integrate 3rd party librariesIIS Express – IIS for the developerBetter Validation – Based on jQuery and
Unobtrusive JavaScript principlesMany small enhancements
Questions ?
TryUpdateModel
Read moreCourse 4282 at Hi-Tech College (Next
Week!!!)
http://weblogs.asp.net/scottgu/http://www.hanselman.com/blog/http://www.asp.net/mvchttp://jquery.com/
Thank You !!!