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 ....