0

如何获取 viewbag 数据,我创建了一个控制器,该控制器从数据库中获取数据并尝试在视图中显示数据,但它不显示数据。

  public ActionResult Show()
    {
        List<Models.Employees> lst = new List<Models.Employees>();
        Models.Employees obj = new Models.Employees();
        DataSet ds =new Models.BL.InsertBL().GetShow(obj);
        lst = (from DataRow drw in ds.Tables[0].Rows
               select new Models.Employees
               {
                   Enames = drw["Ename"].ToString(),
                   DepartId =Convert .ToInt32(drw["Departmentid"]),
                   EmailIds = drw["Emailid"].ToString(),
                   Adress = drw["Address"].ToString()
               }).ToList();
        ViewBag.Sasi = lst; 
        return View();
    }

   @{
    ViewBag.Title = "Show";
     Layout = "~/Views/Shared/VideoLayout.cshtml"; 
      var vv = ViewBag.Sasi;    
    }
4

1 回答 1

3

在这种情况下,我建议您使用强类型视图:

return View(lst);

在视图中:

@model List<Models.Employees>

你的问题,试试这个:

(List<Models.Employees>)ViewBag.Sasi
于 2012-10-30T15:03:22.787 回答