Introduction to ASP. NET MVC

Source: Internet
Author: User

I have been using ASP. net mvc for a while in my formal work. I have also read many other ideas about ASP. NET MVC andCode, I think many people have incorrect understanding of it.

Here I will only talk about some of my ideas about ASP. NET MVC.

1. ASP. net mvc is different from ASP. NET in Design Philosophy

I have heard of ASP. net MVC's first view is ASP. net MVC's biggest feature is the separation of controller and view. At that time, I still didn't understand ASP. net MVC is something, but when I first saw this framework, I thought it was wrong. I think ASP. net MVC has the biggest feature and is also the biggest advantageThe controller is used to drive the development progress of the entire project..

We know that in the object-oriented analysis and design process of a project, we have been focusing on people, roles, and stakeholders to analyze and design the entire project. All are people! People should be at the top of the class design structure, and then we should analyze the characteristics of this person and what we should do (Remember, rather than what this person can do ). That is to say,In addition to the person, the next level should be the behavior of the person, that is, the action in the whole system..

Okay. Let's look back at our initial ASP. in the net webform era, How do we develop a system? We write a bunch of design documents, then the artist gives us the page, and then we often say "set the page ". This is what I did beforeArticle"PDD" (page-driven development ). I will not talk about the disadvantages. I have already made it very clear in the previous article.

So let's think about it. In fact, we will think that webform is a natural product for PDD. When talking about a three-tier architecture, many people have a view that ASP. net itself is a three-tier structure. For the moment, whether this is true or not, it can be explained at least that many people naturally put it. aspx. CS is regarded as one layer, which causes aspx and Aspx. the two layers of Cs are completely coupled.

But where is ASP. net mvc?A user is not accessing a page, but accessing a function (action ).This is the most basic method for Object-Oriented Analysis.

So when developing ASP. net mvc, we shouldFirst, consider what functional blocks we need. This is our controller. Then, under this functional block, what functions do we need? This is our action.As for the page, the function should be used to drive our page development. This is the core of the controller-driven development of the entire project!

However, I think many companies are still using ASP. net to develop the entire project, I think, this is not mastered ASP. net MVC.

ASP. net mvc Key Point 1: first develop the controller. The page is totally shelved, and the Controller rather than page is used to drive the whole project development.

2. Controller Code Organization

In the overall architecture, I personally thinkThe Controller is more like a facade. It provides users with an access interface. Behind this interface is the complex business logic..

However, I have seen that many companies' codes are mixed with complicated business logic in the controller, and even hundreds of lines and thousands of lines of controller may appear, which I cannot understand.

Let's think about the purpose of Facade:Defines a high-level interface, which makes this subsystem easier to use.

In my opinion, pay attention to the following points:

A.The Controller should not contain any private or protected methods., A facade class should only be exposed by external methods,He only integrates other class methods..

B.Action should not process any detailed logic.I personally think that,Each method should only contain the method at the next abstract level, instead of the mixing of abstract layers and the jump of abstract layers..

C. Action itself is actually a method, as mentioned in the code specification,The method should be just a verb or a verb phrase.Instead of using a noun as a method name. BecauseThe user wants to do an action instead of getting something..

3. Last

I felt like there were a lot of things to say, but I did not know what to write. I will talk about it next time.

Finally, I personally suggest learning ASP. NET MVC. You can refer to some mature ideas in the Java field. Some of them are actually very similar to ASP. NET MVC, such as Struts and spring MVC.

I plan to take a look at the next time. You are welcome to discuss and learn together.

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: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.