ViewData的使用


//Controller
public ActionResult Index() { ViewData["Message"] = "欢迎使用 ASP.NET MVC!"; List<string> list= new List<string>(); list.Add("test1"); list.Add("test2"); ViewData["list"] = list; Models.User user = new Models.User(); user.ID = 100; user.Name = "ZG"; ViewData["User"] = user; return View(); }

 

     <%= Html.Encode(ViewData["Message"]) %></h2>
    <%foreach (var item in ViewData["list"] as List<string>) %>
    <% { %>
    <% =item %>
    <%} %>
    <br />
    <% var user = ViewData["User"] as MvcDemo.Models.User;%>
    <%=user.Name%>
    <%=user.ID%>

 

posted on 2012-07-24 14:43  张扬个性,敢为天下先  阅读(6923)  评论(0编辑  收藏  举报