ASP.NET MVC
The Basic Big PictureJuhani Välimäki 12.2.2013
Model
View
Controller
Web ServerBrowser / Client
XHTML pages with form and
input elements. And links
URI mapper Global.asax
Request- protocol, e.g. http://- Server name, e.g.
myy.haaga-helia.fi- Port, e.g. 8080- More URI, e.g.
Controller /Home, Action /Index
- Possible parameters- Verb:GET|POST
Response- XHTML page with links
for sending requests back to Web server
- Possible XHTML form element with input fields and submit elements
- Referenced .css/.jpg/.js etc. files
_Layout.cshtml
Index.cshtml
Action
URI link
Controller’s actions fetch or create the Model, possibly updating it.
Controller passes the (possibly modified) Model to any desired View
The View parses data from the Model to the elements of the View (page) and adds Action links to the page for the next round of Request-Resp
Data
Model
View
Controller
Web ServerBrowser / Client
XHTML pages with form and
input elements. And links
URI mapper Global.asax
_Layout.cshtml
Index.cshtml
Action
URI link
URI mapping- which controller?- which action?- which parameterized
version of the action?
- Any incoming URI can be mapped to any internal URI! All, including the Controller, Action and Parameters, is customizable!
Global.asax config file:- default controllers,
actions & parameters- ways to parse
provided controller, action and/or parameter information
Data
Model
View
Controller
Web ServerBrowser / Client
XHTML pages with form and
input elements. And links
URI mapper Global.asax
_Layout.cshtml
Index.cshtml
Action
URI link
Model could be, e.g.:- Single DTO object- Collection of DTO objects- Complicated object
reference structure- (Interface class or object
for database, even some Business Logic Layer or DAO object)
- Proxy object for so called ORM
Data
Model is passive from MVC point of view- Controller creates or
fetches the Model e.g. from DB/ORM/EDM
- Also the View will be given access to the Model
- (=”Also the View is in control of/knows the Model”)
- Model doesn’t know the Control nor the View
- Yet Model can run code if asked to
Model
View
Controller
Web ServerBrowser / Client
XHTML pages with form and
input elements. And links
URI mapper Global.asax
_Layout.cshtml
Index.cshtml
Action
URI link
View is formed:- From the ”master page” part
/Views/Shared/_Layout.cshtml- View part will be added inside.
E.g. /Views/Home/Index.cshtml is the HomeController’s Index action’s view content
- Possible _Partial views (underscore)- Use Visual Studio to auto-create any
folders or files so that linkages work
Data