Asp.net MVC study Note 1

Source: Internet
Author: User

Since the official release of Asp.net MVC in March 19, it has received much attention, so today I have followed the trend and read the following: Yes, it is quite good. Some ideas are somewhat similar to struts in javaee, the figure below shows that the reposted content is quite understandable.

 

I will describe that URL submission is intercepted by the ing system and will be matched according to the ing rules in (Global. asax,

 

Routes. ignoreroute ("{resource}. axd/{* pathinfo }");

Routes. maproute (
"Default", // route name
"{Controller}/{action}/{ID}", // URL with Parameters
New {controller = "home", Action = "Index", id = ""} // parameter defaults
);

This is the default route rule (you can also set it yourself.

After the interception, the root rule obtains the controllername (controllername is the name of the controller removed from the class inherited from the Controller. For example, if you have a usercontroller and the name of the control class ing is user)

If this controller is found, the method in the Controller class will be searched (that is, the return type is actionresult). The method name is determined by the controing after controllername. The above rule can be followed by parameters, or not added. The default value is null.

Then the method is executed. The method returns an actionresult type and searches for the corresponding view based on the result.

Note: The view page does not seem to be created at will. For example, if there is a usercontroller above, the view page corresponding to it should be in the view folder (default) search under the user folder (corresponding to the usercontroller name)

The simplest example

 

File structure:

 

// Put a user name to viewdata.

Public class democontroller: Controller
{
 

Public actionresult index ()
{
Viewdata ["username"] = "zhangsan ";
Return view ("Index ");
}

}

 

The index. ASPX page displays the user name.

<Div>
User name:
<% = Viewdata ["username"]. tostring () %>
</Div>

Access path: http: // localhost: 13595/demo/Index

The demo is the democontroller prefix.

Index is the method index in democontroller.

 

Post-feeling: I personally think this kind of drive type is a bit similar to struts. Find the action with this name through reflection based on the name and perform some business processing to return a value. This value determines the page or action to return. Well, I just saw this feeling for half an hour! For more information, see ....

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.