Common methods for data transmission between Controller and View in MVC, mvccontroller

Source: Internet
Author: User

Common methods for data transmission between Controller and View in MVC, mvccontroller

I have been learning MVC over the past few days. By the way, I will record my daily learning experience and share it with you!

In MVC, data transmission between the Controller and View is very frequent, so here we will summarize several common methods I have used in learning:

 

Forward data from the Controller to the View:

ViewData: a set of Key/Value dictionaries.

Assignment Method (in the cs file ):

ViewData ["Demo"] = "Hello world! ";

Usage (in the aspx file ):

<H1> <%: ViewData ["demo"] %>  

 

Pass data from the View to the Controller:

Method 1: Use FormCollection type parameters to obtain data

Public ActionResult Index (FormCollection collection) {string str = collection ["demo"]; // str = "hello world! "Return View ();}

Method 2: Use Request [key] to obtain data

Public ActionResult Index () {string str = Request ["demo"]; // str = "hello world! "Return View ();}

 

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.