Introduction to Asp.NET MVC

0

MVC article-1-picture-3

Hello Readers, I hope all of you enjoyed the series of “Create Notepad using C# and windows form” I which we discuss various control and using that we create our own Notepad. Now from this we starts with a latest technology ASP.NET MVC for the development of web application .in this article we only discuss the three different technology for creating web application in short and then the advantage of using ASP.NET over them.

The three technology for creating web application in ASP.NET are
1. ASP.NET Web Form
2. ASP.NET Web Page
3. ASP.Net MVC
ASP.NET Web Form: This technology allow you to create web application in the same way you would create a window application. This means just like in windows application here also you have following two files for each page

 

1. A user interface file: This is where you design your application and add control that we use on our page and show how our application look like. This file has the extension .aspx.

2. A code behind file:This files includes the code that handle of the events and all the C# or VB code associated with the user interface file is keep separate in this file so that the designing code and logical code not get mixed and the complexity of programming decreases. The extension of this file depends upon the language we use, if use C# then extension is .aspx.cs and if use VB.NET then extension is .aspx.vb .

To work efficiently in web form it is necessary to understand the page life cycle of web form, that we discuss in my second article of “ASP.NET Page life cycle”. All the events from preinit to unload is dicussed in detail in that article so go through from that article to get the detailed summary of page life cycle.

An ASP.NET web application contain several type of file and each type serves a different purpose. Following table lists and describe the most important files used.

MVC article-1-picture-1

ASP.NET Web Pages :ASP.NET web pages is framework for building web application in which pages use the razor syntax from MVC 3.0, before it the rendering engine used is aspx view engine .In this concept you embed the server side code to your web page. Razor page uses the extension .cshtml or .vbhtm depending upon the language choice (C# and VB.NET ). As the code is embedded in the web page so the idea of code behind does not exist in this type. The content of Razor page is created with html so no server control like is available in this.

You can use visual studio to create web pages but main tools used for the creation of web pages is Microsoft Web Matrix. In Microsoft Web Matrix you have access to web helper which let your application to use common services such as Twitter, reCApTCHA, Bing map and more. Web matrix also include SQL server compact edition, a light weight and free database solution. It also support window azure.

In the web pages we used the word razor several time, Now we discuss what is razor engine and what is aspx engine and what is difference between them.

MVC article-1-picture-2

ASP.NET MVC: ASP.NET MVC is free and fully supportive platform for creating web applications that use model view-controller-pattern. Like ASP.NET web form the ASP.NET MVC built on the platform of ASP.NET means you can use in ASP.NET MVC applications the same APIs for security, state management, caching and so on that you can use in ASP.NET Web form applications.

Every ASP.NET MVC application has three core parts: a model, views, and controllers. In short, the model consists of all the classes that handle data and business logic. Data processing using model classes is initiated by the controllers that are in charge of user requests. Once the data processing is complete the controller creates a response to the user by sending the results to a View who then produces HTML to be rendered in the browser.

MVC Pattern: The following figure illustrate simple implementation of MVC pattern

MVC article-1-picture-3

Model: The model in MVC pattern represents the parts of the applications that implement the data domain logic. This is simple collection of classes and can be used by making the objects of these classes.

Views: Views are the visible element in the applications application. It shows the user data from the model. A view page receive a view model object from the controller.The view page contain html to determine how to render the model data back to the browser.

Controller: Controller are the classes that collect the user request, work with model and then select a view to rendering.

ASP.NET MVC Benefits:
Compared to web form, ASP.NET MVC application has following benefits
1. The MVC pattern itself makes it easier to manage complexity by clearly separating the functionality of the application into three core parts, the model, the view, and the controller.
2. ASP.NET MVC provides better support for test-driven development (TDD).
3. ASP.NET MVC works well for web applications that are supported by large teams of developers and for web designers who need a high degree of control over the HTML.

Here we end with this article and in this article we discussed about different technology for creating web application and the benefits of ASP.NET MVC over others, we also discussed the MVC pattern briefly.
This is a good start for beginners.In the next article we will discuss about ASP.NET MVC request processing and also check the steps for installing MVC.
Please give your suggestion and feedback.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CommentLuv badge