From İzmir to the digital world.

What Is ASP.NET MVC?

Web & Software 3 min read

What Is ASP.NET MVC?

My previous article briefly explained what MVC is and is not. The basic theory was limited, so I kept it short. From this article onward, we will explore Microsoft's ASP.NET MVC framework, with plenty to discuss and implement. 🙂 Let's begin.

If you use traditional ASP.NET forms and wonder why you should use ASP.NET MVC, read on.

Disadvantages of ASP.NET Forms

ViewState : ViewState has useful features in ASP.NET forms, but it can become very large. Traditional ASP.NET pages use it to preserve form and user state across postbacks, storing this information in Base64 form. Each request may generate tens or hundreds of kilobytes of additional HTML data. This larger page travels to the server and back on postback, consuming considerable bandwidth and slowing page loading for the user.

Page Life Cycle : This mechanism coordinates events between client and server and manages the request-response process. However, it is complex. We can intervene in the page life cycle, but doing so may cause unexpected errors whose causes can be hard to identify.

Uncontrolled HTML Output: Server-side languages generate HTML, and ASP.NET pages return HTML after server processing. Our control over the output is limited, however. Even when the appearance is right, clean HTML meeting W3 standards can be difficult to obtain. The generated code may stray from our intended structure, especially with CSS and JavaScript involved. ASP.NET 4.x improved this issue without eliminating it entirely.

Excessive Code-Behind Dependency : Suppose you develop an N-tier web application with separate presentation and business layers. ASP.NET forms work against this separation because much of the application logic must be written in the presentation pages' code-behind. The resulting scattered code also makes later updates and extensions harder.

Introducing the ASP.NET MVC Framework

MVC is a software architecture pattern known since 1979 and used in many programming languages. Microsoft's ASP.NET MVC Framework lets us use MVC architecture with ASP.NET and continues to be developed.

Model, View and Controller structures and responsibilities in ASP.NET MVC.

Model : This contains database access, classes and data operations using tools such as ADO.NET, NHibernate or Entity Framework in the data access layer.

View : This contains what the user sees: interface elements and HTML, CSS and JavaScript. Business workflow does not belong here. Separating the interface from the application's core makes its design easier to change.

Controller : Controllers receive and process client requests. They execute workflows, handle user interactions, run methods, create variables and objects, and coordinate the model and view. In ASP.NET MVC, controllers are small C# classes derived from System.Web.Mvc.Controller .
Remember: Every view has a controller, but every controller does not need a view.

The diagram above shows the stages of the ASP.NET MVC workflow.

In summary, a client request is processed by a controller. If necessary, it accesses model objects and performs operations there, then returns to the controller. After any final processing, the controller sends the result to the view, and the server response reaches us as HTML.

We will begin practical ASP.NET MVC examples in the next article. Newcomers to MVC should find it especially helpful.

Services, projects, products and knowledge base