public ActionResult Index(int id)
        {
            //ViewData["id"] = id;
            List<string> ls = new List<string> { 
                "123","123456","123456","123456"
            };            ViewData["lll"] = ls;
            return View();
        }
然后我在页面或许到ViewData["lll"] 为空        @if (ViewData["lll"] == null)
        {
            Response.Write("1");
        }
        else
        {
            Response.Write("2");
        }这个输出的结果为1       public ActionResult Index(int id)
        {
            //ViewData["id"] = id;
            List<string> ls = new List<string> { 
                "123","123456","123456","123456"
            };
            return View(ls);
        }
一个朋友跟我说还可以这样写
但是不知道怎么才能在view页面获取到这个ls
csdn上查了View(Object),还是云里雾里
求高手,如何在页面或许到ls

解决方案 »

  1.   


      <% var list=ViewData["lll"] as List<string>;%>  //View(ls)
      <% var list = Model as List<string>; %>
      

  2.   

    View中:
    foreach(User u in (IList<T>)ViewData[""]){...} 
      

  3.   

    <% ViewData["lll"]  %> 应该写在aspx页面的吧
      

  4.   

       <% foreach (Movie m in (IEnumerable)ViewData.Model)
    {}
    后台IList<T> 传过来的 集合  我一般这样写滴  可以出来
      

  5.   


     后台
    IList<Movice>  list ..........
    return view(list);
      

  6.   

    页面中的
    Model 属性
    就是传过去的那个object
    进行一下强制类型转换就可以用了如果想避免类型强转,可以使用派生自泛型的ViewPage<T>
      

  7.   

     public ActionResult Index(int id)
            {
                //ViewData["id"] = id;
                List<string> ls = new List<string> { 
                    "123","123456","123456","123456"
                };
                return View(ls);
            }
    mvc3中在页面头部这样指定
    @model List<string>
    调用时用@Model