0.示例代码
自定义一个控制器
并向view传值 MyName = "LiuYan"
public class FirstController : Controller
{
// GET: First
public ActionResult Index()
{
ViewBag.MyName = "LiuYan";
return View();
}
}
1.
view中使用控制器传过来的值
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
My Name is : @ViewBag.MyName