Tuesday, 17 March 2015

Day 1- Introduction to ASP.NET MVC


MVC is one of three ASP.NET programming models. The other two are Wen Forms, Web Pages and the last One we are going to Study MVC.

MVC is a framework for building web applications using a MVC (Model View Controller) design:

The Model represents the application core (for instance a list of database records).
The View displays the data (the database records).
The Controller handles the input (to the database records).
The MVC model also provides full control over HTML, CSS, and JavaScript.

The MVC model defines web 
applications with 3 logic layers:



The business layer (Model logic)

The display layer (View logic)

The input control (Controller logic)

The Model is the part of the application that handles the logic for the application data.
Often model objects retrieve data (and store data) from a database.

The View is the parts of the application that handles the display of the data.
Most often the views are created from the model data.

The Controller is the part of the application that handles user interaction.
Typically controllers read data from a view, control user input, and send input data to the model.

The MVC separation helps you manage complex applications, because you can focus on one aspect a time. For example, you can focus on the view without depending on the business logic. It also makes it easier to test an application.

The MVC separation also simplifies group development. Different developers can work on the view, the controller logic, and the business logic in parallel.

When to Use ASP.NET MVC
ASP.NET MVC has certain capabilities that make it the best option to choose if you need one or more of the following:

•A high level of control over the generated HTML: Unlike Web Forms, Views in ASP.NET MVC render HTML exactly as you tell them to. Recently, Web Forms have been improved in this area but still don’t have the level of control MVC has.

• Easier unit testing: With ASP.NET MVC, it is very easy to follow testing patterns such as test-driven development (TDD). Because of the complex event life-cycle in Web Forms, on top of a control-based framework, TDD is a lot easier with MVC.

• Separation of concerns: This refers to having all aspects of the system clearly separated from

one another. Because of the pattern it implements, an MVC application is divided into discrete

and loosely bound parts (model, views, and controllers), which makes it easy to maintain.

ASP.NET MVC Request Processing
One of the most important concepts to understand about MVC applications is that no relationship exists between a
page request and a physical file inside the web server. In a traditional Web Forms and Web Pages application, every
page request is translated into a call to a physical file in the webserver. For example, if your request is something like http://myapp/mypage.aspx, the web server interprets the request by looking at the root of the website for a file named mypage.aspx.It then processes the file and returns the generated HTML. 

         A component called routing engine matches the request to a specific route. A route defines requests using a pattern string and establishes the controller and method in the controller class that should process the request. Once the route is identified, the routing engine creates a request handler that in turn will create the controller object that will process the request (in our example, the controller is “product”). The controller then invokes the method in the controller class that will process the request (in the example is named “list”). These methods in controller classes that process
requests are called action methods. When the processing of the request ends, the action method produces a result to send back to the user. Normally the result is some HTML (rendered by a View) the user will see in the browser. We will examine the routing engine in more detail in Day XX. Figure Below illustrates the server-side
processing life cycle in an ASP.NET MVC web application.





No comments:

Post a Comment