(Asp.net mvc learning) Use of View and data transfer between View and Controller

Source: Internet
Author: User

Generally, when a View is created, the corresponding Action name is the same by default and may be different. However, you need to specify the View to be returned using the View () method. The View here generally refers to the page, and of course it cannot be completely expressed as the page.

In the current ASP. net mvc 2 RC version, No. aspx. cs page is available when you create a View using a template. There is only a bare. aspx page. When you create a master page using the MVC template, no code page is available for user controls (partial views. If you need to write some C # code for code separation, use the method used to create the aspx page and inherit the class from System. web. mvc. viewPage. Both the master page and the user control (partial view) must inherit System. web. mvc. viewMasterPage and System. web. mvc. viewUserControl.

When an Action in the Controller transmits a value to a View, there are two ways to transmit data: ViewData and TempData. ViewData is also divided into strong type and weak type transmission. In general, we still use more weak types. ViewData is actually a dictionary. A strong type is used to inherit ViewPage <IViewData> from the View to be passed, so that ViewData becomes a strong type. In addition, TempData, like ViewData, can transmit data to the View. However, TempData can be accessed anywhere, but can only be accessed once. It disappears automatically after access, however, ViewData can only be used in the same agreed View, Partial View, or currently loaded Master page, but it can be used multiple times.

In addition, there are some Helper classes in the View. Some HtmlHelper and UrlHelper can help generate some commonly used html code. Generally, I write them directly using html code, which is more intuitive, these two Helper classes are rarely used. However, I am looking at the scale-up project of asp.net mvc contrib open-source, and I have developed some projects, such as DataHelper, to generate tables. I am not very clear about them. ^-^. I will study it later.

Related Article

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.