//---------------------------------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?