MVC, how does the action method pass data to a view in several ways?

Source: Internet
Author: User

 //---------------------------------Controller passes data to the view         PublicActionResult Transdata () {//1.ViewBagViewbag.hello ="Hello world~~~"; //2.ViewDataviewdata["Think"] ="C #"; //3.TempDatatempdata["temphh"] ="I'm Tempda ."; //4.Model//the Model attribute is essentially Viewdata.modelModels.student entity =NewStudent () {s_name ="Wisdom Podcast Video Learning" }; Viewdata.model=entity; returnView (); }
@{Layout=NULL;}<! DOCTYPE html>"Viewport"Content="Width=device-width"/> <title>TransData</title>@ViewBag. Hello<br/>@ViewData ["Think"]<br/>@TempData ["temphh"]<br/>@Model. S_name @ViewData. model.s_name @* on view, ViewBag share ViewData data, same ViewData share viewbag data *@ @ViewBag. Think @ViewData ["Hello"] @ViewData ["temphh"]    @*//not appearing on the page, you can see that data is not shared between TempData and ViewData and ViewBag *@@ViewBag. Temphh</div></body>

MVC, how does the action method pass data to a view in several ways?

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.