ViewBag用来做视图的值绑定,我不清楚是不是这么称呼。之前看过安卓的值绑定做法,mvc直接动态类型,瞬间逼格满满
Controller:
public class HomeController : Controller { public ActionResult Index() { ViewBag.TryIt = "Hellow ViewBag"; ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application."; return View(); }
View:
<body> <header> <h1>@ViewBag.TryIt</h1> <div class="content-wrapper"> <div class="float-left">
在header里随便测试一下。
结果: