7. • The Routing module is responsible for mapping incoming browser requests to
particular MVC controller actions
• Two places to setup:
Web.config file
Global.asax file
Would you like to use:
/Products.aspx?CategoryID={3F2504E0-4F89-11D3-9A0C-0305E82C3301}
Or:
/Products/Books
7
8. How it works?
The Controller asks the
Model for data
The request hits the
controller
2 Model
1 3
Controller The Model gives the data back
U to the Controller
s
The controller formats the data and
e passes them to the View 4
View
r
5
The view renders the HTML that
needs to be sent to the client
9. • It’s the core of your application
• A place for business logic, data
access, Validation ... etc
• A model is accessible by
both controller and view
• Totally independent from the
views or the controllers
10. Controller [C]
• Heart of the entire
MVC architecture
• Responsible for
Handling user
interaction
12. • Handles the rendering of the view to UI (html);
• Different view engines have different syntax
• ASP.NET MVC3 have following Pre-included View Engines:
Web Forms(ASPX)
Razor
Provides a different coding style than ASPX files.
Files will have a CSHTML/VBHTML
Main goal is to handle embedded .Net code more gracefully.
15. References
•Official website http://asp.net/mvc
•Source Code http://codeplex.com/aspnet
•Blogs
o Scott Guthrie http://weblogs.asp.net/scottgu
o Rob Conrey http://blog.wekeroad.com
o MVC Store Front http://blog.wekeroad.com/mvc-storefront
o Phil Haack http://haacked.com
o Scott Hanselman http://hanselman.com
o Stephen Walthler http://weblogs.asp.net/stephenwalther
Notes de l'éditeur
Here we are going to see following points;What is MVC – Conventional MVC and history of MVCWhy MVC is required i.e. downside of MVCHow MVC works i.e. framework and architecture of MVCRoutingView Engine(Razor)What ASP.NET MVC Can not
It stands for Model view controller, i.e. input logic, business logic, and UI logic these three things plays an essential role in the development of any application Basically this is an design pattern which is being used since long time in programming development ;like JAVA, Ruby on Rails , Python, Spring, Struts,Java and Zend Framework , PHP, Mono RailDesign patternmeans an repeatable solution to commonly occurring problem.- One common programming problem; where we put code, what code goes where etc. MVC is solution that detects how to arrange your code based on what they are doing
Why MVC is required in AS.NETWe have ASP.NET framework having RAD, rich library of controls like gridview, dataltst etc.Viewstate- ViewState maintains the state across postbacks- ViewState is powerful, but it has its drawbacks (weight,…)- Mechanism for maintaining state across requests results in large blocks of data being transferred between the client and server. Hundreds of kilobytes back and forth in every request2. Limited control over HTML- Server controls render as HTML, but not HTML you want; not as per web standard- Server control generate unpredictable and complex IDs values that are hard to access using Javascript3. Page life cycle- Page life cycle can be nightmare, it is very confusing when we uses controls4. Unit Testing- The ASP.NET behind code is completely tied up with ASP.NET Http context object which makes unit testing very difficult. 5. Separation of code & UI- Code behind code is different and the UI is different but then they are only separate physical files and one cannot just exist without other.
A “Framework” built on top of Asp.net core framework. Microsoft has two frameworks for building web applications built on top of the ASP.NET framework: ASP.NET Web Forms and ASP.NET MVC By adapting MVC pattern, ASP.NET MVC framework provides strong competitions to ROR and similar platforms.
Clear separation of logicIt makes it easier to manage complexity by dividing an application into the model, the view, and the controllerWhen you create an new ASP.NET MVC project, visual studio will create project template for us containing standard folder structure where we can put our jssscript,css etc.2. TDD- it provide development along with testingIt provides better support for test-driven development (TDD). Easier to unit test.ASP.NET MVC framework was designed to its core to support unit tests. Web applications written with the ASP.NET MVC framework are highly testableWhen we create new ASP.NET MVC project through visual studio it will provide us to create test project, but this is not compulsory3. No viewstateSo the size of such pages is much less than the same pages generated using the ASP.NET WebForm4. Full control over HTMLAs we have separate presentation layer so we have full control over HTML/cssJavascript developer will pleased to know that ASP.NET MVC meshes so well with jQueryIt is having in built support for jQuery5. ExtensibleModel, View, Controller classes are implemented from interface based technology so all are extremely flexible and extensible.Master page, Forms authentication, Membership and Role providers, Profiles, Internationalization and Cache
How MVC pattern works;User will first request to controllerController class will ask Model for dataModel gives data back to controllerController formats data and passes it to viewView renders HTMLIn MVC, the behind code is moved to a simple .NET class called as controller. Any user request first comes to the controller class; the controller class then invokes the model and attaches the model to the view for display to the end user.
It’s the core of your applicationMVC model is basically a C# or VB.NET classA place for business logic, data access, Validation ... etc.A model is accessible by both controller and view and can be used to pass data from Controller to viewTotally independent from the views or the controllers
Heart of the entire MVC architectureController is basically a C# or VB.NET class which inherits system.mvc.controllerConsisting of a set of action methods which are responsible for responding to browser OR calling views.Controller are responsible for Handling user interactionController can access and use model class to pass data to viewsController uses ViewData to pass any data to view
View is an ASPX page or CSHTML without having a code behind fileResponsible for presentation, look & feel, formatting, sorting … etc. All page specific HTML generation and formatting can be done inside viewA request to view can be made only from a controller’s action methodNo View State, No Server ControlsCan be extended by implementing View Engines
ASP.NET WebForm’ssubstitute Fit RADFit every projectFit everyone