1 / 23

ASP MVC

ASP MVC. http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/intro-to-aspnet-mvc-4. 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

lise
Download Presentation

ASP MVC

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ASP MVC http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/intro-to-aspnet-mvc-4

  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. 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. 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 know

  5. MVC and ASP • MVC 4 is the version supplied with VS 2012 • MVC 5 is supplied with VS 2013

  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. 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. Reasons NOT to use MVC • It’s complicated • You must live in the MVC structure

  9. MVC The ModelFrom Wikipedia

  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. 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. MVC Routes (2)

  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. Razor Syntax (1) • Code is added using the @ character and enclosed in braces • Statements end with a semicolon • Code is case sensitive

  15. Razor Syntax (2) • There are many redefined objects Request, Response… just as in asp.net

  16. Razor Syntax (3) • Decision making and loops are supported

  17. The MVC Model (1) • The model contains all of the business logic for the application • It’s just a class that contains properties and methods • These methods and properties, in turn, are referenced by the controller

  18. The MVC Model (2) • Model properties and method

  19. 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

  20. Create an MVC Application (1)

  21. Create an MVC Application (2)

  22. MVC Application (Structure) • First, the system calls Application.Start • This sets up the “routings”

  23. Application startup • Register routes sets up the default controller • We usually need not mess with it

More Related