SlideShare a Scribd company logo
 
Introducing the ASP.NET MVC framework Maarten  Balliauw –  Real Dolmen Website:  www.realdolmen.com   E-mail:  [email_address]   Blog:  http://blog.maartenballiauw.be
AGENDA MVC ASP.NET MVC Hello world! Routing Extensibility Testing …
MVC – MODEL-VIEW-CONTROLLER Design pattern Isolating business logic from UI Maintainability Layering for UI layer
ASP.NET MVC A new  option  for ASP.NET Simpler  way to program ASP.NET Easily  testable  and TDD friendly More control over your <html/> More control over your URLs Not for everyone! (car vs. motorcycle) Not a replacement for webforms! Supports existing ASP.NET features
WHAT YOU WILL LOSE… Viewstate Postbacks Tricky interview questions about nuances of the page lifecycle
HOW IT WORKS… Browser Web Server http://myserver.com/Products/Edit/5 http://myserver.com/Products/
INTERACTIONS /Products/Edit/5 ProductsController (Controller) /Products/Update/5 URL:
DEMO Hello World
WHAT’S THE POINT? It’s not WebForms 4.0! It’s an  alternative Flexible Extendible in each part of the process Fundamental Only System.Web!  (Not WPF or Winforms) Plays well with others NHibernate for models, NVelocity for views, Unity for dependency injection, … Keep things simple!
GOALS Maintain Clean Separation of Concerns Easy Testing  Red/Green TDD  Highly maintainable applications by default Extensible and Pluggable Support replacing any component of system Source available on CodePlex Not open source Build your own, private version
DRIVING GOALS Enable clean URLs and SEO SEO friendly URL structures Great ASP.NET integration All providers are supported Membership, Caching, Session, … ASP.NET designer in VS2008 Check my blog! http://tinyurl.com/maarten-outputcache http://tinyurl.com/maarten-mvcsitemap
REQUEST LIFECYCLE Browser requests /Products/ Route is determined Controller is activated Method on Controller is invoked Controller does some stuff Renders View, passing in ViewData
ACTUALLY, THERE’S MORE… You can replace each step of the process!
DEMO Request lifecycle
ROUTING – PRETTY URLS Developer adds Routes to a global RouteTable Mapping creates RouteData – a bag of key/values This is  NOT  URL rewriting! It’s more! public static void RegisterRoutes(RouteCollection routes) {   routes.MapRoute( &quot;Default &quot;{controller}/{action}/{id}&quot;,  new { controller = &quot;Home&quot;, action = &quot;Index&quot;, id = &quot;&quot; }, new { controller = @&quot;[^\.]*&quot; } ); }
CUSTOM URL ROUTING Can setup custom URL routing rules within the RegisterRoutes() method in Global.asax Enables very flexible mapping and route rules: Default parameters Constraints Named routes Wildcard “catch-all” routes
DEMO Routing
EXTENSIBILITY These are all pluggable! Views Controllers Models Routes Check my blog! http://tinyurl.com/maarten-mvccustomviewengine MvcContrib http://www.codeplex.com/MvcContrib
VIEWENGINE, VIEW View engines instantiate views Views render output You get WebForms by default Can implement your own MvcContrib has them for Brail, NHaml, NVelocity, … Customizing these can be used to Offer new DSLs to make HTML easier Generate totally different mime/types Images, RSS, JSON, XML, OFX, VCards, DOCX, whatever public abstract class VirtualPathProviderViewEngine : IViewEngine { protected abstract IView CreatePartialView(...); protected abstract IView CreateView(…); } public interface IView { void Render(ViewContext viewContext, TextWriter writer); }
NHAML – FROM… <%@ Page Language=&quot;C#&quot; MasterPageFile=&quot;~/Views/Shared/Site.Master&quot; AutoEventWireup=&quot;true&quot;  CodeBehind=&quot;List.aspx&quot; Inherits=&quot;MvcApplication5.Views.Products.List&quot; Title=&quot;Products&quot; %> <asp:Content ContentPlaceHolderID=&quot;MainContentPlaceHolder&quot; runat=&quot;server&quot;> <h2><%= ViewData.CategoryName %></h2> <ul> <% foreach (var product in ViewData.Products) { %> <li> <%= product.ProductName %>  <div class=&quot;editlink&quot;> (<%= Html.ActionLink(&quot;Edit&quot;, new { Action=&quot;Edit&quot;, ID=product.ProductID })%>) </div> </li> <% } %> </ul> <%= Html.ActionLink(&quot;Add New Product&quot;, new { Action=&quot;New&quot; }) %> </asp:Content>
NHAML – TO… http://code.google.com/p/nhaml/ %h2= ViewData.CategoryName  %ul  - foreach (var product in ViewData.Products)   %li = product.ProductName    .editlink   = Html.ActionLink(&quot;Edit&quot;,    new { Action=&quot;Edit&quot;,    ID=product.ProductID })    = Html.ActionLink(&quot;Add New Product&quot;,    new { Action=&quot;New&quot; })
SPARK – FROM… <%@ Page Language=&quot;C#&quot; MasterPageFile=&quot;~/Views/Shared/Site.Master&quot; AutoEventWireup=&quot;true&quot;  CodeBehind=&quot;List.aspx&quot; Inherits=&quot;MvcApplication5.Views.Products.List&quot; Title=&quot;Products&quot; %> <asp:Content ContentPlaceHolderID=&quot;MainContentPlaceHolder&quot; runat=&quot;server&quot;> <h2><%= ViewData.CategoryName %></h2> <ul> <% foreach (var product in ViewData.Products) { %> <li> <%= product.ProductName %>  <div class=&quot;editlink&quot;> (<%= Html.ActionLink(&quot;Edit&quot;, new { Action=&quot;Edit&quot;, ID=product.ProductID })%>) </div> </li> <% } %> </ul> <%= Html.ActionLink(&quot;Add New Product&quot;, new { Action=&quot;New&quot; }) %> </asp:Content>
SPARK – TO… http://dev.dejardin.org/ <viewdata model=&quot;MvcApplication5.Models.Product“/> <h2>${ViewData.CategoryName}</h2> <ul>   <for each=&quot;var product in ViewData.Products&quot;>   <li> ${product.ProductName}   <div class=&quot;editlink&quot;>   (<a href=&quot;/Products/Edit/${product.ProductID}&quot;>Edit</a>)   </div> </li> </for> </ul> <a href=&quot;/Products/New&quot;>Add New Product</a>
FILTER ATTRIBUTES Enable custom behavior to be added to Controllers and Controller actions 4 types Authentication filter Action filter Result filter Exception filter Examples: [Authorize], [LogAction], [OutputCache], … http://tinyurl.com/maarten-outputcache
DEMO Filter attributes
TESTING Has anyone tried testing webforms? Without IIS being fired up? Each component tested individually?
INTERFACES AND TESTING These are all easily mockable! HttpContextBase, HttpResponseBase, HttpRequestBase Extensibility  IController IControllerFactory IRouteHandler IViewEngine
TESTING CONTROLLER ACTIONS No requirement to test within ASP.NET runtime! Can mock parts of runtime you want to fake Using Moq, Rhino, TypeMock, … http://code.google.com/p/moq/ [TestMethod] public void ShowPostsDisplayPostView()  { BlogController controller = new BlogController(…); var result = controller.ShowPost(2) as ViewResult; Assert.IsNotNull(result); Assert.AreEqual(result.ViewData[ &quot; Message &quot; ],  &quot; Hello &quot; ); }
TESTING CONTROLLER ACTIONS USING MOQ [TestMethod] public void TestInvalidCredentials() { LoginController controller = new LoginController(); var mock = new Mock<System.Web.Security.MembershipProvider>(); mock.Expect(m => m.ValidateUser(&quot;&quot;, &quot;&quot;)).Returns(false); controller.MembershipProviderInstance = mock.Object; var result = controller.Authenticate(&quot;&quot;, &quot;&quot;) as ViewResult; Assert.IsNotNull(result); Assert.AreEqual(result.ViewName, &quot;Index&quot;); Assert.AreEqual(controller.ViewData[&quot;ErrorMessage&quot;], &quot;Invalid credentials! Please verify your username and password.&quot;); }
TESTING FRAMEWORKS Any framework is supported! Visual Studio Test NUnit XUnit …
DEMO Testing
DEMO A complete application!
SUMMARY A new option for ASP.NET. More control over your <html/> and URLs More easily testable approach Not for everyone – only use it if you want to Shipping later this year
COMMON QUESTIONS Should I use WebForms or MVC? Are there any controls? Do I have to write <%= %> code in my view? What about AJAX? How fast/scalable is it? Is it safe? When will it ship?
QUESTIONS?
THANK YOU! Make sure to check http://blog.maartenballiauw.be/category/MVC.aspx

More Related Content

What's hot (20)

PDF
Usability in the GeoWeb
Dave Bouwman
 
PPTX
Introduction to angular js for .net developers
Mohd Manzoor Ahmed
 
PPTX
Testing C# and ASP.net using Ruby
Ben Hall
 
PPTX
Angularjs Live Project
Mohd Manzoor Ahmed
 
PDF
Web driver selenium simplified
Vikas Singh
 
PDF
Fullstack End-to-end test automation with Node.js, one year later
Mek Srunyu Stittri
 
PDF
Laravel mail example how to send an email using markdown template in laravel 8
Katy Slemon
 
PDF
Introduction to Using PHP & MVC Frameworks
Gerald Krishnan
 
PDF
JavaFX Advanced
Paul Bakker
 
PPT
Rey Bango - HTML5: polyfills and shims
StarTech Conference
 
PDF
Node.js and Selenium Webdriver, a journey from the Java side
Mek Srunyu Stittri
 
PPTX
Migrating from JSF1 to JSF2
tahirraza
 
PDF
JavaFX in Action (devoxx'16)
Alexander Casall
 
PDF
API Technical Writing
Sarah Maddox
 
PDF
OSDC 2009 Rails Turtorial
Yi-Ting Cheng
 
PPTX
Add even richer interaction to your site - plone.patternslib
Wolfgang Thomas
 
PDF
Beginning AngularJS
Troy Miles
 
PPT
Perlbal Tutorial
Takatsugu Shigeta
 
PDF
A tech writer, a map, and an app
Sarah Maddox
 
PPT
What's new and exciting with JSF 2.0
Michael Fons
 
Usability in the GeoWeb
Dave Bouwman
 
Introduction to angular js for .net developers
Mohd Manzoor Ahmed
 
Testing C# and ASP.net using Ruby
Ben Hall
 
Angularjs Live Project
Mohd Manzoor Ahmed
 
Web driver selenium simplified
Vikas Singh
 
Fullstack End-to-end test automation with Node.js, one year later
Mek Srunyu Stittri
 
Laravel mail example how to send an email using markdown template in laravel 8
Katy Slemon
 
Introduction to Using PHP & MVC Frameworks
Gerald Krishnan
 
JavaFX Advanced
Paul Bakker
 
Rey Bango - HTML5: polyfills and shims
StarTech Conference
 
Node.js and Selenium Webdriver, a journey from the Java side
Mek Srunyu Stittri
 
Migrating from JSF1 to JSF2
tahirraza
 
JavaFX in Action (devoxx'16)
Alexander Casall
 
API Technical Writing
Sarah Maddox
 
OSDC 2009 Rails Turtorial
Yi-Ting Cheng
 
Add even richer interaction to your site - plone.patternslib
Wolfgang Thomas
 
Beginning AngularJS
Troy Miles
 
Perlbal Tutorial
Takatsugu Shigeta
 
A tech writer, a map, and an app
Sarah Maddox
 
What's new and exciting with JSF 2.0
Michael Fons
 

Viewers also liked (20)

PPTX
ASP.NET MVC Wisdom
Maarten Balliauw
 
PPTX
Just another Wordpress weblog, but more cloudy
Maarten Balliauw
 
PPTX
Mocking - Visug session
Maarten Balliauw
 
PPTX
AZUG.BE - Azure User Group Belgium - First public meeting
Maarten Balliauw
 
PPTX
PHP And Silverlight - DevDays session
Maarten Balliauw
 
PPTX
PHPExcel
Maarten Balliauw
 
PPTX
MSDN - Converting an existing ASP.NET application to Windows Azure
Maarten Balliauw
 
PPTX
Presentation Thesis Big Data
Natan Meekers
 
PPT
MSDN - ASP.NET MVC
Maarten Balliauw
 
PDF
Bài 6 an toàn hệ thống máy tính
MasterCode.vn
 
PDF
Bài 3: Lập trình giao diện điều khiển & Xử lý sự kiện - Lập trình winform - G...
MasterCode.vn
 
PDF
Bài 5: Làm quen với lập trình CSDL ASP.NET - Giáo trình FPT - Có ví dụ kèm theo
MasterCode.vn
 
PDF
Bài 7: Lập trình với CSDL – Sử dụng DESIGNER & Triển khai ứng dụng - Lập trìn...
MasterCode.vn
 
PDF
Bài 4: Lập trình với CSDL ADO.NET & Kiến trúc không kết nối & Lập trình giao ...
MasterCode.vn
 
PDF
Bài 6: Điều khiển DetailsView, FormView, ListView, DataPager
MasterCode.vn
 
PDF
Bài 1 - Làm quen với C# - Lập trình winform
MasterCode.vn
 
PDF
BÀI 2: Thiết kế FORM và xử lý sự kiện - Giáo trình FPT
MasterCode.vn
 
PDF
Apache Hadoop YARN - Enabling Next Generation Data Applications
Hortonworks
 
PDF
Lập trình ứng dụng web asp.net với C# - tailieumienphi.edu.vn
tailieumienphi
 
PDF
Lập trình sáng tạo creative computing textbook mastercode.vn
MasterCode.vn
 
ASP.NET MVC Wisdom
Maarten Balliauw
 
Just another Wordpress weblog, but more cloudy
Maarten Balliauw
 
Mocking - Visug session
Maarten Balliauw
 
AZUG.BE - Azure User Group Belgium - First public meeting
Maarten Balliauw
 
PHP And Silverlight - DevDays session
Maarten Balliauw
 
MSDN - Converting an existing ASP.NET application to Windows Azure
Maarten Balliauw
 
Presentation Thesis Big Data
Natan Meekers
 
MSDN - ASP.NET MVC
Maarten Balliauw
 
Bài 6 an toàn hệ thống máy tính
MasterCode.vn
 
Bài 3: Lập trình giao diện điều khiển & Xử lý sự kiện - Lập trình winform - G...
MasterCode.vn
 
Bài 5: Làm quen với lập trình CSDL ASP.NET - Giáo trình FPT - Có ví dụ kèm theo
MasterCode.vn
 
Bài 7: Lập trình với CSDL – Sử dụng DESIGNER & Triển khai ứng dụng - Lập trìn...
MasterCode.vn
 
Bài 4: Lập trình với CSDL ADO.NET & Kiến trúc không kết nối & Lập trình giao ...
MasterCode.vn
 
Bài 6: Điều khiển DetailsView, FormView, ListView, DataPager
MasterCode.vn
 
Bài 1 - Làm quen với C# - Lập trình winform
MasterCode.vn
 
BÀI 2: Thiết kế FORM và xử lý sự kiện - Giáo trình FPT
MasterCode.vn
 
Apache Hadoop YARN - Enabling Next Generation Data Applications
Hortonworks
 
Lập trình ứng dụng web asp.net với C# - tailieumienphi.edu.vn
tailieumienphi
 
Lập trình sáng tạo creative computing textbook mastercode.vn
MasterCode.vn
 
Ad

Similar to Introduction to ASP.NET MVC (20)

PPTX
Asp.Net Mvc
micham
 
PPTX
Hanselman lipton asp_connections_ams304_mvc
denemedeniz
 
PDF
ASP.NET MVC 2.0
Buu Nguyen
 
PPS
Introduction To Mvc
Volkan Uzun
 
PPTX
Introduction to ASP.Net MVC
Sagar Kamate
 
PDF
Mvc3 crash
Melick Baranasooriya
 
PPTX
MVC & SQL_In_1_Hour
Dilip Patel
 
PDF
ASP.NET MVC - Whats The Big Deal
Venketash (Pat) Ramadass
 
PPT
ASP.NET MVC introduction
Tomi Juhola
 
PDF
Asp.Net MVC Framework Design Pattern
maddinapudi
 
PPT
ASP .net MVC
Divya Sharma
 
PPTX
Developing ASP.NET Applications Using the Model View Controller Pattern
goodfriday
 
PPT
CTTDNUG ASP.NET MVC
Barry Gervin
 
PPTX
Asp.Net MVC3 - Basics
Saravanan Subburayal
 
PPTX
Day7
madamewoolf
 
PPTX
ZZ BC#7.5 asp.net mvc practice and guideline refresh!
Chalermpon Areepong
 
PDF
Mastering asp.net mvc - Dot Net Tricks
Gaurav Singh
 
PPTX
Asp.Net MVC Intro
Stefano Paluello
 
PPT
ASP.net MVC CodeCamp Presentation
buildmaster
 
PPTX
MVC Training Part 1
Lee Englestone
 
Asp.Net Mvc
micham
 
Hanselman lipton asp_connections_ams304_mvc
denemedeniz
 
ASP.NET MVC 2.0
Buu Nguyen
 
Introduction To Mvc
Volkan Uzun
 
Introduction to ASP.Net MVC
Sagar Kamate
 
MVC & SQL_In_1_Hour
Dilip Patel
 
ASP.NET MVC - Whats The Big Deal
Venketash (Pat) Ramadass
 
ASP.NET MVC introduction
Tomi Juhola
 
Asp.Net MVC Framework Design Pattern
maddinapudi
 
ASP .net MVC
Divya Sharma
 
Developing ASP.NET Applications Using the Model View Controller Pattern
goodfriday
 
CTTDNUG ASP.NET MVC
Barry Gervin
 
Asp.Net MVC3 - Basics
Saravanan Subburayal
 
ZZ BC#7.5 asp.net mvc practice and guideline refresh!
Chalermpon Areepong
 
Mastering asp.net mvc - Dot Net Tricks
Gaurav Singh
 
Asp.Net MVC Intro
Stefano Paluello
 
ASP.net MVC CodeCamp Presentation
buildmaster
 
MVC Training Part 1
Lee Englestone
 
Ad

More from Maarten Balliauw (20)

PPTX
Bringing nullability into existing code - dammit is not the answer.pptx
Maarten Balliauw
 
PPTX
Nerd sniping myself into a rabbit hole... Streaming online audio to a Sonos s...
Maarten Balliauw
 
PPTX
Building a friendly .NET SDK to connect to Space
Maarten Balliauw
 
PPTX
Microservices for building an IDE - The innards of JetBrains Rider - NDC Oslo...
Maarten Balliauw
 
PPTX
Indexing and searching NuGet.org with Azure Functions and Search - .NET fwday...
Maarten Balliauw
 
PPTX
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...
Maarten Balliauw
 
PPTX
JetBrains Australia 2019 - Exploring .NET’s memory management – a trip down m...
Maarten Balliauw
 
PPTX
.NET Conf 2019 - Indexing and searching NuGet.org with Azure Functions and Se...
Maarten Balliauw
 
PPTX
CloudBurst 2019 - Indexing and searching NuGet.org with Azure Functions and S...
Maarten Balliauw
 
PPTX
NDC Oslo 2019 - Indexing and searching NuGet.org with Azure Functions and Search
Maarten Balliauw
 
PPTX
Approaches for application request throttling - Cloud Developer Days Poland
Maarten Balliauw
 
PPTX
Indexing and searching NuGet.org with Azure Functions and Search - Cloud Deve...
Maarten Balliauw
 
PPTX
Approaches for application request throttling - dotNetCologne
Maarten Balliauw
 
PPTX
CodeStock - Exploring .NET memory management - a trip down memory lane
Maarten Balliauw
 
PPTX
ConFoo Montreal - Microservices for building an IDE - The innards of JetBrain...
Maarten Balliauw
 
PPTX
ConFoo Montreal - Approaches for application request throttling
Maarten Balliauw
 
PPTX
Microservices for building an IDE – The innards of JetBrains Rider - TechDays...
Maarten Balliauw
 
PPTX
JetBrains Day Seoul - Exploring .NET’s memory management – a trip down memory...
Maarten Balliauw
 
PPTX
DotNetFest - Let’s refresh our memory! Memory management in .NET
Maarten Balliauw
 
PPTX
VISUG - Approaches for application request throttling
Maarten Balliauw
 
Bringing nullability into existing code - dammit is not the answer.pptx
Maarten Balliauw
 
Nerd sniping myself into a rabbit hole... Streaming online audio to a Sonos s...
Maarten Balliauw
 
Building a friendly .NET SDK to connect to Space
Maarten Balliauw
 
Microservices for building an IDE - The innards of JetBrains Rider - NDC Oslo...
Maarten Balliauw
 
Indexing and searching NuGet.org with Azure Functions and Search - .NET fwday...
Maarten Balliauw
 
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...
Maarten Balliauw
 
JetBrains Australia 2019 - Exploring .NET’s memory management – a trip down m...
Maarten Balliauw
 
.NET Conf 2019 - Indexing and searching NuGet.org with Azure Functions and Se...
Maarten Balliauw
 
CloudBurst 2019 - Indexing and searching NuGet.org with Azure Functions and S...
Maarten Balliauw
 
NDC Oslo 2019 - Indexing and searching NuGet.org with Azure Functions and Search
Maarten Balliauw
 
Approaches for application request throttling - Cloud Developer Days Poland
Maarten Balliauw
 
Indexing and searching NuGet.org with Azure Functions and Search - Cloud Deve...
Maarten Balliauw
 
Approaches for application request throttling - dotNetCologne
Maarten Balliauw
 
CodeStock - Exploring .NET memory management - a trip down memory lane
Maarten Balliauw
 
ConFoo Montreal - Microservices for building an IDE - The innards of JetBrain...
Maarten Balliauw
 
ConFoo Montreal - Approaches for application request throttling
Maarten Balliauw
 
Microservices for building an IDE – The innards of JetBrains Rider - TechDays...
Maarten Balliauw
 
JetBrains Day Seoul - Exploring .NET’s memory management – a trip down memory...
Maarten Balliauw
 
DotNetFest - Let’s refresh our memory! Memory management in .NET
Maarten Balliauw
 
VISUG - Approaches for application request throttling
Maarten Balliauw
 

Recently uploaded (20)

PDF
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 

Introduction to ASP.NET MVC

  • 1.  
  • 2. Introducing the ASP.NET MVC framework Maarten Balliauw – Real Dolmen Website: www.realdolmen.com E-mail: [email_address] Blog: http://blog.maartenballiauw.be
  • 3. AGENDA MVC ASP.NET MVC Hello world! Routing Extensibility Testing …
  • 4. MVC – MODEL-VIEW-CONTROLLER Design pattern Isolating business logic from UI Maintainability Layering for UI layer
  • 5. ASP.NET MVC A new option for ASP.NET Simpler way to program ASP.NET Easily testable and TDD friendly More control over your <html/> More control over your URLs Not for everyone! (car vs. motorcycle) Not a replacement for webforms! Supports existing ASP.NET features
  • 6. WHAT YOU WILL LOSE… Viewstate Postbacks Tricky interview questions about nuances of the page lifecycle
  • 7. HOW IT WORKS… Browser Web Server http://myserver.com/Products/Edit/5 http://myserver.com/Products/
  • 8. INTERACTIONS /Products/Edit/5 ProductsController (Controller) /Products/Update/5 URL:
  • 10. WHAT’S THE POINT? It’s not WebForms 4.0! It’s an alternative Flexible Extendible in each part of the process Fundamental Only System.Web! (Not WPF or Winforms) Plays well with others NHibernate for models, NVelocity for views, Unity for dependency injection, … Keep things simple!
  • 11. GOALS Maintain Clean Separation of Concerns Easy Testing Red/Green TDD Highly maintainable applications by default Extensible and Pluggable Support replacing any component of system Source available on CodePlex Not open source Build your own, private version
  • 12. DRIVING GOALS Enable clean URLs and SEO SEO friendly URL structures Great ASP.NET integration All providers are supported Membership, Caching, Session, … ASP.NET designer in VS2008 Check my blog! http://tinyurl.com/maarten-outputcache http://tinyurl.com/maarten-mvcsitemap
  • 13. REQUEST LIFECYCLE Browser requests /Products/ Route is determined Controller is activated Method on Controller is invoked Controller does some stuff Renders View, passing in ViewData
  • 14. ACTUALLY, THERE’S MORE… You can replace each step of the process!
  • 16. ROUTING – PRETTY URLS Developer adds Routes to a global RouteTable Mapping creates RouteData – a bag of key/values This is NOT URL rewriting! It’s more! public static void RegisterRoutes(RouteCollection routes) { routes.MapRoute( &quot;Default &quot;{controller}/{action}/{id}&quot;, new { controller = &quot;Home&quot;, action = &quot;Index&quot;, id = &quot;&quot; }, new { controller = @&quot;[^\.]*&quot; } ); }
  • 17. CUSTOM URL ROUTING Can setup custom URL routing rules within the RegisterRoutes() method in Global.asax Enables very flexible mapping and route rules: Default parameters Constraints Named routes Wildcard “catch-all” routes
  • 19. EXTENSIBILITY These are all pluggable! Views Controllers Models Routes Check my blog! http://tinyurl.com/maarten-mvccustomviewengine MvcContrib http://www.codeplex.com/MvcContrib
  • 20. VIEWENGINE, VIEW View engines instantiate views Views render output You get WebForms by default Can implement your own MvcContrib has them for Brail, NHaml, NVelocity, … Customizing these can be used to Offer new DSLs to make HTML easier Generate totally different mime/types Images, RSS, JSON, XML, OFX, VCards, DOCX, whatever public abstract class VirtualPathProviderViewEngine : IViewEngine { protected abstract IView CreatePartialView(...); protected abstract IView CreateView(…); } public interface IView { void Render(ViewContext viewContext, TextWriter writer); }
  • 21. NHAML – FROM… <%@ Page Language=&quot;C#&quot; MasterPageFile=&quot;~/Views/Shared/Site.Master&quot; AutoEventWireup=&quot;true&quot; CodeBehind=&quot;List.aspx&quot; Inherits=&quot;MvcApplication5.Views.Products.List&quot; Title=&quot;Products&quot; %> <asp:Content ContentPlaceHolderID=&quot;MainContentPlaceHolder&quot; runat=&quot;server&quot;> <h2><%= ViewData.CategoryName %></h2> <ul> <% foreach (var product in ViewData.Products) { %> <li> <%= product.ProductName %> <div class=&quot;editlink&quot;> (<%= Html.ActionLink(&quot;Edit&quot;, new { Action=&quot;Edit&quot;, ID=product.ProductID })%>) </div> </li> <% } %> </ul> <%= Html.ActionLink(&quot;Add New Product&quot;, new { Action=&quot;New&quot; }) %> </asp:Content>
  • 22. NHAML – TO… http://code.google.com/p/nhaml/ %h2= ViewData.CategoryName %ul - foreach (var product in ViewData.Products) %li = product.ProductName .editlink = Html.ActionLink(&quot;Edit&quot;, new { Action=&quot;Edit&quot;, ID=product.ProductID }) = Html.ActionLink(&quot;Add New Product&quot;, new { Action=&quot;New&quot; })
  • 23. SPARK – FROM… <%@ Page Language=&quot;C#&quot; MasterPageFile=&quot;~/Views/Shared/Site.Master&quot; AutoEventWireup=&quot;true&quot; CodeBehind=&quot;List.aspx&quot; Inherits=&quot;MvcApplication5.Views.Products.List&quot; Title=&quot;Products&quot; %> <asp:Content ContentPlaceHolderID=&quot;MainContentPlaceHolder&quot; runat=&quot;server&quot;> <h2><%= ViewData.CategoryName %></h2> <ul> <% foreach (var product in ViewData.Products) { %> <li> <%= product.ProductName %> <div class=&quot;editlink&quot;> (<%= Html.ActionLink(&quot;Edit&quot;, new { Action=&quot;Edit&quot;, ID=product.ProductID })%>) </div> </li> <% } %> </ul> <%= Html.ActionLink(&quot;Add New Product&quot;, new { Action=&quot;New&quot; }) %> </asp:Content>
  • 24. SPARK – TO… http://dev.dejardin.org/ <viewdata model=&quot;MvcApplication5.Models.Product“/> <h2>${ViewData.CategoryName}</h2> <ul> <for each=&quot;var product in ViewData.Products&quot;> <li> ${product.ProductName} <div class=&quot;editlink&quot;> (<a href=&quot;/Products/Edit/${product.ProductID}&quot;>Edit</a>) </div> </li> </for> </ul> <a href=&quot;/Products/New&quot;>Add New Product</a>
  • 25. FILTER ATTRIBUTES Enable custom behavior to be added to Controllers and Controller actions 4 types Authentication filter Action filter Result filter Exception filter Examples: [Authorize], [LogAction], [OutputCache], … http://tinyurl.com/maarten-outputcache
  • 27. TESTING Has anyone tried testing webforms? Without IIS being fired up? Each component tested individually?
  • 28. INTERFACES AND TESTING These are all easily mockable! HttpContextBase, HttpResponseBase, HttpRequestBase Extensibility IController IControllerFactory IRouteHandler IViewEngine
  • 29. TESTING CONTROLLER ACTIONS No requirement to test within ASP.NET runtime! Can mock parts of runtime you want to fake Using Moq, Rhino, TypeMock, … http://code.google.com/p/moq/ [TestMethod] public void ShowPostsDisplayPostView() { BlogController controller = new BlogController(…); var result = controller.ShowPost(2) as ViewResult; Assert.IsNotNull(result); Assert.AreEqual(result.ViewData[ &quot; Message &quot; ], &quot; Hello &quot; ); }
  • 30. TESTING CONTROLLER ACTIONS USING MOQ [TestMethod] public void TestInvalidCredentials() { LoginController controller = new LoginController(); var mock = new Mock<System.Web.Security.MembershipProvider>(); mock.Expect(m => m.ValidateUser(&quot;&quot;, &quot;&quot;)).Returns(false); controller.MembershipProviderInstance = mock.Object; var result = controller.Authenticate(&quot;&quot;, &quot;&quot;) as ViewResult; Assert.IsNotNull(result); Assert.AreEqual(result.ViewName, &quot;Index&quot;); Assert.AreEqual(controller.ViewData[&quot;ErrorMessage&quot;], &quot;Invalid credentials! Please verify your username and password.&quot;); }
  • 31. TESTING FRAMEWORKS Any framework is supported! Visual Studio Test NUnit XUnit …
  • 33. DEMO A complete application!
  • 34. SUMMARY A new option for ASP.NET. More control over your <html/> and URLs More easily testable approach Not for everyone – only use it if you want to Shipping later this year
  • 35. COMMON QUESTIONS Should I use WebForms or MVC? Are there any controls? Do I have to write <%= %> code in my view? What about AJAX? How fast/scalable is it? Is it safe? When will it ship?
  • 37. THANK YOU! Make sure to check http://blog.maartenballiauw.be/category/MVC.aspx