asp mvc s/mvc-4/getting-started-with- aspnet-mvc4/intro-to-aspnet- mvc-4
Post on 19-Dec-2015
222 views
TRANSCRIPT
ASP MVC
http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/intro-to-aspnet-mvc-4
Slide 2
Introduction (1) MVC (Model View Controller) uses a
common design (architectural) pattern to build web applications We could have an endless talk about
design patterns Refer to the GOF
It’s not a new concept. MVC was introduced in the 1970
Slide 3
Introduction (2) The model gets requests from the
controller and sends back data The model knows things
The view gets data from the control and is responsible for rendering The view shows the things the model
knows
The model implements application logic
Slide 4
Introduction (3) The controller plays the largest role
It sends requests to the model and gets back data
That data is passed on to the appropriate view
It gets and interprets requests from clients
It gets commands from the users and tells the view what to show and the model what to do
Slide 5
MVC and ASP MVC 4 is the version supplied with VS
2012 MVC 5 is supplied with VS 2013
Slide 6
MVC and ASP You can use Razor to build the user
interface We can also use ASP forms
It’s a very different beast than ASP.NET Web forms There is no view-state for example
MVC and Web Forms can be used in the same application
Slide 7
Reasons to use MVC Easy to test Component-based Modules are very plug and play
There is no view state or server forms It’s up to you
Slide 8
Reasons NOT to use MVC It’s complicated You must live in the MVC structure
Slide 9
MVC The ModelFrom Wikipedia
Slide 10
MVC (URLs) You are used to URLs pointing to a
physical resources An HTML document An aspx file Or something….
URLs work much differently in MVC We route names to physical URLs By default, the parts of a URL are special
If this sounds restful – it is.
Slide 11
MVC Routes (1) Routes provide the mechanism to map
URLs into a corresponding call to a controller function
Roughly speaking, the format of a route is
{controller}/{action}/{id}
Slide 12
MVC Routes (2)
Slide 13
MVC Views Views provide the display engine in the
MVC model You create them in two ways
As traditional ASP.NET Web forms Using Razor
In a sentence, Razor is really not much more than mutated PHP
Slide 14
The MVC Model (2) Model properties and method
Slide 15
MVC Controllers The controller does the work It reads and writes data from the model
(via properties and methods It sends data to the view
Slide 16
Create an MVC Application (1)
Slide 17
Create an MVC Application (2)
Slide 18
MVC Application (Structure) First, the system calls Application.Start This sets up the “routings”
Slide 19
Application startup Register routes sets up the default
controller We usually need not mess with it