Building Web Sites With: Israr Ali
Building Web Sites With: Israr Ali
Model
View Controller
Separation Of Concerns
• Each component has one responsibility
• SRP : Single Responsibility Principle
7
Model
• Set of classes that describes the data we are
working with as well as the business
• Rules for how the data can be changed and
manipulated
• May contain data validation rules
• Often encapsulate data stored in a database as
well as code used to manipulate the data
• Most likely a Data Access Layer of some kind
• Apart from giving the data objects, it doesn't have
significance in the framework
8
View
• Defines how the application’s user interface (UI) will be displayed
• May support master views (layouts) and sub-views (partial views or
controls)
• Web: Template to dynamically generate HTML
9
Controller
• The core MVC component
• Process the requests with the help of views and models
• A set of classes that handles
• Communication from the user
• Overall application flow
• Application-specific logic
• Every controller has one or more "Actions"
10
MVC Frameworks
• CakePHP (PHP)
• CodeIgniter (PHP)
• Spring (Java)
• Perl: Catalyst, Dancer
• Python: Django, Flask, Grok
• Ruby: Ruby on Rails, Camping, Nitro, Sinatra
• JavaScript: AngularJS, JavaScriptMVC, Spine
• ASP.NET MVC (.NET Framework)
11
ASP.NET Core
ASP.NET
Caching .NET Globalization
12
Clean URLs
• REST-like
• /products/update
• /blog/posts/2013/01/28/mvc-is-cool
• Friendlier to humans
• /product.aspx?catId=123 or post.php?id=123
• Becomes /products/chocolate/
• Friendlier to web crawlers
• Search engine optimization (SEO)
13
ASP.NET MVC Request
14
The Technologies
• Technologies that ASP.NET MVC uses
• C# (OOP, Unit Testing, async, etc.)
• HTML(5) and CSS
• JavaScript (jQuery, KendoUI, etc.)
• AJAX, Single-page apps
• Databases (MS SQL)
• ORM (Entity Framework and LINQ)
• Web and HTTP
15
Demo
MVC First Steps
What MVC is not ?
Controller
Request
Step 1
Incoming request directed to Controller
MVC Flow
Controller
Model
Step 2
Controller processes request and forms a data Model
MVC Flow
Controller
View
Step 3
Model is passed to View
MVC Flow
Controller
View
Step 4
View transforms Model into appropriate output format
MVC Flow
Controller
View
Response
Step 5
Response is rendered
Request Flow – in more detail
Request
HTTP Http
Routing Controller Response
Handler
Route View
Route View
Handler Engine
Routing Engine
• URLs -> application -> Controller Action
• Construct outgoing URLs
• Constructed URLs can be used to call back to
Controllers/Actions
Demo
Routing
Summary
• Not a replacement for WebForms
• All about alternatives
• Fundamental
• Part of the System.Web namespace
• Same team that builds WebForms
Additional Resources
• Official sites
• Central landing site: http://asp.net/mvc
• Forums: http://forums.asp.net/1146.aspx
• Source available
• Source drop: http://codeplex.com/aspnet
• Blogs
• http://blogs.microsoft.co.il/blogs/noam
• http://weblogs.asp.net/scottgu
• http://hanselman.com/
• http://haacked.com/