ASP. NET MVC vs Web Form

Source: Internet
Author: User
Tags classic asp what is asp

Translator Introduction

Little. NET schoolchildren, tick ... Tick... The rain ...

The text is as follows =======================================================

source Example (VS2012):

1. Download Simple WebForm demo-6.7 KB

2. Download Simple MVC Demo demo-1.5 MB


I have been an ASP. NET developer for a long time, and I am very happy to use ASP. NET Web Forms to develop Web applications.

Microsoft published the ASP. NET MVC framework for the first time in 2008. I was very surprised "why need another ASP." And a lot of people and I have the same idea.

Many people say that the ASP. NET Framework will replace the ASP. NET Web forms framework, but this is not true. They each have their advantages and disadvantages, and no one tells or teaches us what kind of architecture to use, but we can discuss some facts that will help us choose the framework that best suits the needs of the project.

Together we will try to find the answers to some questions, such as

l what is ASP.

l What is ASP. NET Web Forms?

L What is MVC?

l What is ASP. NET MVC?

If you're a high-level or experienced ASP. NET MVC developer, you already know that MVC is great, and this article will help you to keep these concepts warm.

Discussion content


ü Visualization Technology

Üweb Technology

Üweb Visualization Technology

ü What is ASP.

ü What is Web Forms?

Ü 4.0

ü What is MVC?

ü What is ASP. NET MVC?

How does ü MVC work?

ü What is the ASP. NET Web forms framework and what is the ASP.

    1. Visualization technology

Microsoft has put forward the so-called "visualization" technology, with the help of this technology, Microsoft can quickly develop graphical user applications. Features like drag-and-drop and smart hints allow developers to focus more on the implementation of the application's business functions rather than the UI design.

    1. Web Technology

The current more classic web technologies are: Asp,php,jsp,ror, Web forms, MVC and so on. ASP is a classic Web technology introduced by Microsoft, the biggest problem of ASP is chaotic code layout and poor maintainability.

Let's assume a scenario where you have some text and a button that validates the data on the server when the button is clicked, if the validation succeeds in the database, and if the validation fails, the error message is displayed on the form with a red label. Do you know what the biggest problem with this scene is? You have to do a lot of things yourself to achieve this effect.

1) First, you set the Action property of the form to point to the current page itself.

2) The value of the text box will be automatically emptied after the button is clicked, so you can only try to recover from the submitted data yourself.

3) If the server verification fails, you must

A) extract the corresponding value from the submitted data to the corresponding text box;

b) display error messages;

(Asynchronous commit using Ajax is another way to do this, but here I'm explaining that it takes a lot of manual work in the classic ASP technology)

    1. Web Visualization Technology

Like Visual Basic technology is limited to separate applications, when it comes to networking, there is only the choice of Microsoft Classic ASP.

When we talk about Web applications and WinForm applications, there are two things to consider:

1) How does state management work?

2) How does the request/response work?

The Web application follows the HTTP protocol. The HTTP protocol is stateless, that is, the same client's request and the last request is not the corresponding relationship, for the HTTP server, it does not know that the two requests from the same client. Unlike WinForm applications, no variables will be saved, and there is no complete event-driven programming model. The same as the WinForm application is the need to wait for user input, but each user's input and interaction will be sent to the server as a new request (Get/post).

In the end, Microsoft proposed the so-called ASP. NET Web forms framework, which takes into account the needs of rapid application development and simple and easy to learn.

    1. What is ASP.

Asp. NET is a Web application framework for Microsoft, a dynamic Web site built by the common language runtime (Clr,common language Runtime) in a programming language such as C # or It supports two modes: Web forms and ASP.

    1. What is Web Forms?

Microsoft published ASP solves many of the problems in ASP by creating a higher level of abstraction on the web in a stateless and model-simulating state for the developer. New concepts such as "self postback" (submitting form data to this page), "ViewState" (maintaining view state during the postback callback), etc. are introduced in the Web Forms framework. In the Web Forms framework, Microsoft has tried to introduce a visual model into Web application development.

Let's discuss the pros and cons of the Web Forms framework:

1) Advantages:

A) Web forms supports rich server controls

When using a simple HTML client control, you may notice that the display of the browser terminal control is not always consistent. For example: A UI looks great in Internet Explorer, but it's bad in Firefox. Asp. NET server control detects the type of browser and generates the corresponding HTML and JavaScript.

Many server controls like the GridView and ListView can bind data, thereby reducing the amount of code written.

b) Support view state

You may have heard "HTTP is a stateless protocol" several times. Typically, controls do not persist control values between multiple requests. However, in the Web Forms framework, "stateful" is achieved by having the current form page in the form of "hidden fields" for each control state, which is the view state.

c) Event-driven programming

It provides us with:

L Code-behind (Code post-implant) technology enables the separation of display logic and processing logic in ASP. aspx pages that point to CS files, which facilitates the creation of Web applications. such as division of labor, art and programming can be a dry, no longer like the previous ASP as the background code and HTML code are mixed together, difficult to maintain.

L Auto-postback mechanism (self postback mechanism)

L ViewState (view state)

Developers no longer rely on the Post,get method to handle user-server interactions, eg: you can drag controls onto a page (such as a button), and simply double-click the control to generate the corresponding background code to process the user's click Logic on the server.

d) Rapid Application development

Rich server controls, event-driven models, and view-state greatly increase the speed of development, and developers will be transparent about the complex implementation behind it, allowing them to focus more on the business logic of the application.

e) Low learning costs

Developers who use powerful server controls and view state can develop practical applications without the need for too much HTML and JavaScript skills.

2) Disadvantages

A) Project structure

When you create a Web Forms application, there is no predefined project schema. Developers have the flexibility to choose the project architecture they want. You can choose a basic three-tier architecture to divide the system into the presentation layer (UI), the Business Logic layer (BLL), the data layer (DAL), or the more advanced MVP (Model-view-presenter) architecture. You can also choose to use only code-behind technology to write all the logic here, but this is not a good project architecture scenario.

b) Unit Test

In the Code-behind technology of the Web Forms architecture, a large number of event handlers are used to make it impossible to automate unit testing.

Note: As far as I know, the "Sender" and "EventArgs" two objects in the event handler cannot be simulated even with the help of a simulation test (MOQ or RHINOMOQ).

Importantly, test-driven development and unit testing are now becoming more and more important.

c) Performance

ViewState successfully solved some problems in the classic ASP program, but also introduced some other problems. ViewState is stored in the page itself, which increases the size of the page to reduce program performance.

D) reusability

Let's discuss another example, we build two UI

L Tax Employee page

L Non-Taxable Employees page

Now the two pages will share most of the background business logic. After creating a page, create a second page by adding some if-judging criteria.

This would violate the single principle of responsibility for the design of a program, i.e. a class, with only one cause for its change. There should be only one duty. Each responsibility is an axis of change, and if a class has more than one responsibility, these responsibilities are coupled together. This can lead to fragile designs. When a duty changes, other responsibilities may be affected. In addition, multiple responsibilities are coupled together, which can affect reusability. For example, to achieve separation of logic and interface.

e) cannot fully control HTML

In the Web forms architecture, many times we cannot determine the HTML generated by server controls in the terminal browser, which makes it difficult to integrate third-party JavaScript libraries, such as jquery.

f) SEO

The URL points to a specific ASPX page and may also contain some query strings. This is not friendly for search engines. More details: "More friendly website URL design"

g) Lack of parallel development support

ASPX pages and background code files are tightly coupled, so it is not convenient for 2 developers to develop both the page and the background code.

    1. ASP. 4.0

ASP. NET 4.0 released some new features to address some of the issues mentioned above.

1) ViewState: Provides the ability to disable or control the view state size.

2) URL routing: Using URL routing, we can provide our own URL instead of the physical path of the page.

3) ID: In asp.net4.0, we can better control the id attribute of the element in order to better integrate with other JavaScript libraries. (However, we do not have complete control over the generation of HTML elements)

Although after significant improvements in asp.net4.0:

1) still can't solve the unit test problem.

2) I have never seen developers who use the ASP. NET Web Forms schema attempt to disable viewstate. (This is a personal opinion)

3) We can control the id attribute of an element, but we can't completely control how HTML is generated, so there are some difficulties in programming with third-party JavaScript libraries.

    1. What is MVC?

MVC is an architectural pattern that is now used in many places.

Many people use it in Java. Microsoft introduced it into the ASP. NET MVC architecture. We'll discuss the ASP. NET MVC architecture today, but before we do, we'll look at some of the terminology in MVC.

1) Mode: In fact, it is the methodology to solve a certain kind of problem. Summarize the method of solving some kind of problem to the theoretical height, that is the pattern. The pattern is a guide that, under a good guide, helps you to accomplish the task and helps you to make a good design plan to achieve a multiplier effect. And will get the best solution to the problem.

2) Architectural Mode: Schema mode is also called architectural style, an architectural pattern describes the basic structure of the software system organization or outline, is to solve our problems from the subsystem level or module level. We often need to build class libraries, builds, Web services, and so on.

3) MVC: When we talk about applications, there are elements of input logic, business logic, UI logic, and so on. MVC is an architectural pattern that allows us to keep these logical elements loosely coupled as we develop our applications.

The main intent of the MVC pattern is to detach the focus, which separates the presentation or UI from the business or user interaction logic.

The MVC system should be divided into M (Model), V (View) and C (Controller).

The L Model, which is positioned as intelligent or manual business rules, Logic, data, is independent of the MVC view and controller parts.

The Controller, which receives and assigns requests made by the user interaction logic or input logic, needs to know the model and view of MVC.

L View, which is positioned as the output representation of the model data, may be an Excel table, a Web page that displays a list of records, or a simple text. It just needs to know the model of MVC.

    1. What is ASP. NET MVC?

ASP. NET MVC was released by Microsoft to design a low-coupling, testable Web application framework built on the CLR and the mature MVC architecture. ASP. NET MVC does not support ViewState and server controls, so you may think that you are back in trouble with native Web application development. But no, let's discuss the pros and cons of the ASP. NET MVC framework:


1) Project Structure

The ASP. NET MVC architecture reduces the coupling between programs, that is, M (model), V (View), C (Controller).

2) test-driven development and re-usability

A) The controller of MVC is a standalone class, so it supports test-driven development.

b) The controller of MVC, which does not bind to any particular view, can be re-used for multiple view.

3) Performance

The ASP. NET MVC framework does not support viewstate, so there is no automatic state management mechanism, which reduces the size of page delivery and improves program performance.

4) Full HTML control

ASP. NET MVC does not support server controls, and the only option is to use the client input controls so that we have complete control over the last displayed HTML. So the ASP. NET MVC architecture can be easily integrated with third-party JavaScript libraries (eg:jquery).

5) Support parallel development

The layers in the ASP. NET MVC architecture are loosely coupled, so one developer develops the controller while the second developer develops the view and the third developer develops the model. This is known as parallel development.

6) Seo,url rewrite and rest

Rich routing rules allow each URL to be treated as a resource, that is, to support restful.

At the same time, users with good, readable URLs can improve the SEO.

7) Scalable

ASP. NET MVC supports a variety of view engines, eg:aspx, Razor, and, if needed, the ability to develop their own view engines.

8) inherit the ASP. NET attribute

Built on a well-established ASP. NET Framework, the ASP framework provides developers with many good features, such as form validation, Windows authentication, caching, sessions, and so on.


1) Increased learning costs

There is no event-driven programming model and view state, making it difficult for developers who lack the experience of web application development to get started.

    1. How does ASP. NET MVC work?

1) The user requests some resources from the browser URL to the server. (GET Request)

2) The routing engine first passes this request to the corresponding controller.

3) If persistent data is required, the controller obtains the data from the model.

4) model accesses the database data (or some other data resource) and returns the data to the controller.

5) Controller will select the appropriate view.

6) The controller passes the data (the model obtained in fourth) to the page (the view acquired by the fifth), and the data is populated to the specified position on the page.

7) The Controller returns the view and renders it to the user.

This is a GET request, and the process for the post request is similar. The only difference is that instead of typing the URL trigger in the browser, you do something on the page (eg: click the button, change the drop-down option, and so on) to trigger the POST request.

I didn't even notice that I had a good view of the garden friends. Ha ha... Do not change the original translation, it is here to explain it.

    1. What is the ASP. NET Web forms framework and what is the ASP.

Which one is the "best choice"? A specific solution relies on the needs of the application and the technical background of the team members. When you face the need to choose one in the ASP. NET Web Forms framework and the ASP. NET MVC framework, you have to understand that the most important weights are not technology, but others. When you make a choice, you need to consider two important factors:

1) Rapid Application development

If you want to develop any WEB program quickly, then the ASP. NET Web Forms framework is your only option, and you don't even have to think about how to get the ASP to develop programs quickly. (The reason for selecting the asp: The requirement is a fast-developing program that the customer typically does not pay too much money, or if the application uses only one, two months and no longer need to maintain the project)

2) Unit Test

If automated unit testing is important to you, it is best to choose the ASP. NET MVC framework.

In addition to this, you can do this by writing down your project requirements and trying to compare the advantages and disadvantages of the ASP. NET Web Forms framework and ASP. If possible, try asking yourself the following questions:

1) Does your team have extensive development experience on the Web Forms framework or the Windows Forms framework?

If so, learning the ASP. NET MVC framework can be a tedious task for a team. Because developers are accustomed to using ViewState and event-driven programming models, thinking changes will be a difficult task. Get a vote------the WEB forms framework.

2) Does your team have extensive development experience in the ASP. NET MVC framework?

If yes, select the MVC framework. Get one vote------the ASP.

3) Does your team have extensive development experience in ASP or non-Microsoft technologies (such as Android, iOS, JSP, Ror, PHP, etc.)?

If you've ever used a JSP or ASP, you might be familiar with the Get and post requests for HTTP, and even you might have written code that uses MVC patterns, because most of these technologies use the MVC pattern by default. Get one vote------the ASP.

4) Do you use JavaScript extensively?

If so, it's more appropriate to choose the MVC framework because it gives you full control over the HTML of the page. Get one vote------the ASP.

5) Looking for better performance

The ASP. NET MVC framework, which does not support the ViewState mechanism, provides better performance than the net Web Forms framework. The ASP. NET MVC Framework gets a vote.

6) plan to reuse the same input logic

If yes, select the MVC framework. Get one vote------the ASP.


I think you should prepare sufficient information to decide what is best for your project. The final decision depends on your team and your project needs.

I hope you like this article, thank you for your patience to read.

hahaha, translation to this end, good text also please more help recommend ... Recommended.

Original Marla Sukesh

Original link: Http://

Recommended reading:

Why MVC is Better? Translation

A Few good reviews:

@ Passing by Autumn

5) Looking for better performance

The ASP. NET MVC framework, which does not support the ViewState mechanism, provides better performance than the net Web Forms framework. The ASP. NET MVC Framework gets a vote.


The performance point is not the problem of not supporting ViewState, WebForm can also disable viewstate, and MVC in order to design the need, from the beginning to traverse all referenced assemblies, to get to all control to call the corresponding method, is based on reflection call.

Therefore, it is not simple to ViewState VS reflection who performance better.

The specific performance depends on the developer's water rating.

@wowhy reply @ Passing Autumn

WebForm also has a large number of reflection calls, such as a DataGrid binding or something.

As long as the server control is used, there is no way to avoid the expansion of HTML transport bytes, plus a variety of server events, the small white use is simply a disaster. In my opinion, the greatest benefit of MVC is to let users understand the nature of the web, look at all kinds of HTML, JAVASCRIPT, CSS.


MVC feels more appropriate for the web, easier to combine with other JS frameworks, easier to understand and control, and more control over the HTML itself.

MVC also has a lot of UI controls, such as Telerik,kendoui, which are not as stupid as webform those controls, but more manageable, and this control is not meant to be easy to use, but rather easier to take control of actions and processes, and it is easier to manipulate them when there is a need for personalization.

@ Deep Sea Sink

Correcting the author of the original, the current ASP. NET MVC or the model in Spring MVC is not the model in the traditional MVC model. The model in the traditional MVC model is to get the data, contain the business logic, and the ASP. NET MVC or Spring MVC model is actually a data container, the controller will get the data (or already mdoel) into the model, Passed to view, the model is simply a container for data, without any business logic. The author of the original works must have made a mistake.


Pointing out a bit of blog post error, the ASPX view engine for the ASP. NET. NET MVC Framework also supports server-side controls. (Razor view engine is not supported)

@ Liu

To do biased Internet applications, MVC is really much better than webform, there are no server controls those drawbacks.

But WebForm in enterprise management and other applications have the advantage of MVC, and now are relatively mature, business management does not need a gorgeous interface, rarely go with jquery, the general point JS, and WebForm custom control, ActiveX, etc. now is not a bit can put off, Generally do enterprise application, to my experience, basically are webform.

ASP. NET MVC vs Web Form

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.