Download presentation
Presentation is loading. Please wait.
1
ASP MVC http://www.asp.net/mvc/tutorial s/mvc-4/getting-started-with- aspnet-mvc4/intro-to-aspnet- mvc-4
2
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
3
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
4
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
5
Slide 5 MVC and ASP MVC 4 is the version supplied with VS 2012 MVC 5 is supplied with VS 2013
6
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
7
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
8
Slide 8 Reasons NOT to use MVC It’s complicated You must live in the MVC structure
9
Slide 9 MVC The Model From Wikipedia
10
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.
11
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}
12
Slide 12 MVC Routes (2)
13
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
14
Slide 14 The MVC Model (2) Model properties and method
15
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
16
Slide 16 Create an MVC Application (1)
17
Slide 17 Create an MVC Application (2)
18
Slide 18 MVC Application (Structure) First, the system calls Application.Start This sets up the “routings”
19
Slide 19 Application startup Register routes sets up the default controller We usually need not mess with it
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.