View generation in ASP. NET MVC

Source: Internet
Author: User

In ASP. net mvc, we divide the front-end presentation into three independent parts for implementation. The Controller is used to control user operations, the View is used to control the presentation content, and the Model is used to represent the processed data. From the Controller to the view, in the Controller, we define multiple actions. The return type of each Action is generally ActionResult. At the end of the Action processing, we return a call to the view. Public ActionResult Index () {return this. view ();} by default, a View with the same name as the Action will be called. For example, a View named Index will be used in the preceding Action. If we pass a string parameter, the string will be considered as the view name. For example, if we want to use the view named IndexView for rendering, we can do the following. Public ActionResult Index () {return this. View ("IndexView");} Will the layout and View MVC go directly to our View? No! After the Action is returned, MVC first checks whether a special file named _ ViewStart. cshtml exists in the Views folder. If yes, It executes the file again. By default, the content of this file is as follows: @ {Layout = "~ /Views/Shared/_ Layout. cshtml ";} That is, it sets our default Layout to use that file. The layout is equivalent to the master page we use in WebForm. If this file is not available, no layout is used by default. What if we don't want to use this layout on the page with this file? It's easy to set Layout = null on the page to overwrite it. @ {Layout = null;} partitions in the Layout are displayed on the Layout page. By default, a special instruction @ RenderBody () exists, will be output here. This is why

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.