First knowledge of MVC

Source: Internet
Author: User

I. MVC and ASP. NET MVC Basic Concepts
    • MVC is an acronym for Model-view-controller.
    • MVC divides the application into 3 components: Model \ View \ Controller.
    • MVC is not unique to ASP. Struts2 in Java is also an MVC model.
    • Since the release of ASP. 1.0 In 2008, the latest version of ASP. NET MVC, as of 2014, is already 5.0.
    • Since the 1.0 version of ASP. NET MVC has been open source code (source address: aspnetwebstack.codeplex.com).
    • ASP. NET MVC website address: HTTP://WWW.ASP.NET/MVC
Second, the relationship between the three components of MVC
    • Views and models can be invoked directly in the controller
    • The model can be called in the view.
    • Model cannot invoke view
    • The model can qualify the data used in the view, but the model used in the view should be provided by the Controller
    • The controller can be called in the view (called by the form's submission in the view and by clicking on the hyperlink)
Relationship between ASP. NET WebForm model and ASP. NET MVC Model
    • Both are development models built on the ASP. So some of the features in ASP. NET can be shared by both.
    • The WebForm programming model is a typical event-driven web model, while MVC is not.
    • The URL address of the WebForm is file system-based, and MVC is action-based.
Iv. conventions in ASP.
    • All controllers must be placed in the Controllers folder
    • All controller class names must end with controllers
    • All models should be placed in the models directory.
    • All view files should be placed in the views directory.
    • All controllers classes should inherit from the Controller class (essentially inheriting the IController interface)
    • The public method in the Controller class becomes action (behavior)
    • If the view file is not found in the corresponding view directory, the view file with the same name in the views\shared directory will be searched
    • Return view () in action, by default, returns the same file as the action name.
    • The default route (named Default) is registered in the Global.asax global application class, and the default route specifies that the controller defaults to Home,action by default to index.   The parameter ID is optional. So in the URL address if you do not enter a controller default access to the home controller, if you do not enter the action default access to the ACTION.HTTP://LOCALHOST:54321/name index Explanation: According to the default route rule, equivalent to = = Http://localhost:54321/Home/Index
    • HTTP://LOCALHOST:54321/HOME/INDEX/5 Explanation: The value 5 is automatically mapped to the parameter named ID in the action.
    • Http://localhost:54321/Home/Index/5?name=jack&age=20 Explanation: The parameters include ID, name, and age three
Other

In the view file, there is a name called the Model property, which refers to the data that is passed from the action. In order to use model data, we also need to set the type of the model data in the ASPX view <% @Page the Inherits property of the%> directive. Set the model type in the Razor view ...

First knowledge of MVC

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.