mvc5 利用viewbag.一个页面使用几个MODEL的内容
最简单将主的是model返回,其他的用viewbag.赋值。
string username = Session["username"].ToString(); ///取出session的usernme的值 var listcmsusers = (db.ListCMSUsers.Where(x => x.Id == id)).ToList(); //if (listcmsusers !=null) if(listcmsusers.Any()) { var xxx = listcmsusers.Where(z => z.UserName == username); if (xxx != null) { ViewBag.ListUsers = listcmsusers;
前台
@foreach (jsdhh2.Models.ListCMSUser data in (ViewBag.ListUsers as IEnumerable<jsdhh2.Models.ListCMSUser>)) { <li> <img src=@data.HeadPicUrl class="img-circle" /> <i>@data.UserName</i> </li> <li> <a href="#"> <img src=@data.HeadPicUrl style="width: 78px; height: 78px; border-radius: 100%;"> <i>@data.UserName</i> </a> </li> }