www.twitter.com/telerik www.facebook.com/telerik CONTROLLING ASP.NET MVC 4 Philip Japikse (@skimedic) phil.japikse@telerik.com www.skimedic.com/blog MVP, MCSD.Net, MCDBA, CSM, CSP Agile Practices Evangelist, Telerik
WHO AM I? Agile Practices Evangelist, Telerik, Inc. Microsoft MVP, MCSD, MCDBA, CSM, CSP Lead Director, Cincinnati.NET User s Group Founder, Agile Conferences, Inc. Host, Zero To Agile Podcast www.telerik.com/zerotoagile 8/30/2012 2
CONFIGURATION CHANGES 4/19/2008 3
APP_START New folder holds: AuthConfig BundleConfig FilterConfig RouteConfig WebApiConfig 4/19/2008 4
GLOBAL.ASAX CHANGES protected void Application_Start() { //area registration, etc WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); AuthConfig.RegisterAuth(); } 4/19/2008 5
DEMO CONFIGURATION CHANGES 4/19/2008 6
UPDATED TEMPLATES
ASP.NET MVC STARTER PROJECTS Intranet Starter website that uses forms authentication Internet Starter website that uses Windows authentication Richer UI Mobile Includes KnockoutJS, JQueryUI Optimized for Mobile Devices WebAPI Includes JQueryMobile HTTP Service Application 8
STARTER SITES 9
RICHER UI 10
MVC TEMPLATES IN RTM MVC templates are changed! No longer have responsive UI
ADAPTIVE RENDERING MEDIA QUERIES @media only screen and (max-width: 850px) {.. } NOTE: @media is a CSS3 element rendered by the browser, not a MVC4 specific item 12
DEMO IMPROVED TEMPLATES
MOBILE
HTML5 - IN THE BOX <ul data-role="listview" data-inset="true"> <li data-role="list-divider">navigation</li> <li>@html.actionlink("home", "Index", "Home")</li> <li>@html.actionlink("contact", "Contact", "Home")</li> </ul>
VIEWPORT META TAG <meta name="viewport" content="width=device-width" />
ADD JQUERY MVC TO INTERNET APPS (NuGet) Install-Package jquery.mobile.mvc Adds: _Layout.Mobile.cshtml _ViewSwitcher.cshtml ViewSwitcherController.cs
VIEW SWITCHING
CREATING DISPLAY MODES DisplayModeProvider.Instance.Modes.Insert(0, { new DefaultDisplayMode("iPhone") ContextCondition = (context => context.getoverriddenuseragent().indexof("iphone", StringComparison.OrdinalIgnoreCase) >= 0) });
DEMO DISPLAY MODES, VIEW SWITCHING, BROWSER OVERRIDING
ASYNC
TASK SUPPORT - ASYNC CONTROLLERS Async action methods Written as single methods Return Task or Task<ActionResult> Support for Timeouts Add CancellationToken parameter
ASYNC CONTROLLERS public class HomeController : AsyncController { public async Task<ActionResult> Index() { var client = new HttpClient(); var response = await client.getasync( Url.Action("gallery", "photo", null, Request.Url.Scheme)); var jss = new JavaScriptSerializer(); var result = jss.deserialize<list<photo>>( } } await response.content.readasstringasync()); return View(result);
HANDLING TIMEOUTS [AsyncTimeout(5000)] [HandleError(ExceptionType = typeof(taskcanceledexception), View = "TimedOut")]
DEMO ASYNC
WEBAPI
ASP.NET WEB API Modern HTTP Programming Model Routing Content Negotiation Model Binding and Validation Filters Query Composition Improved Testability Improved Inversion of Control Code-Based configuration Self-Hostable
DEMO WEBAPI
ADD WEBAPI CONTROLLER Derives from API Controller
WHAT S NOT IN MVC4 (YET) ASP.NET Single Page Application (postponed) SignalR (postponed) Run Recipe Removed from VS
UPGRADING MVC3 PROJECTS Create new MVC4 Project Copy Views, Controllers, Code, Content Update all web config files System.Web.MVC -> Version 4 System.Web.WebPages -> Version 2 System.Web.Helpers -> Version 2 System.Web.WebPages.Razor -> Version 2 Follow: http://www.asp.net/whitepapers/mvc4-release-notes 4/19/2008 31
BREAKING CHANGES Removed from Razor ModelSpan, Mvc<Language>RazorCodeGenerator, MvcVBRazorCodeParser WebMatrix takes over URL for Forms Auth Breaks MVC RTM applications Requires MVC3 Tools Update or Manual updates from http://www.asp.net/whitepapers/mvc4-release-notes 4/19/2008 32
CONTACT ME phil@telerik.com www.skimedic.com/blog www.twitter.com/skimedic www.telerik.com/zerotoagile 8/30/2012 33