如何在MVC中查看列表对象?

11 浏览
0 Comments

如何在MVC中查看列表对象?

在控制器页面上:\n

object likes = (from p in ctx.Profiles
                join sl in ctx.SuggestionLikes on p.UserId equals sl.UserId
                join s in ctx.Suggestions on sl.SuggestionId equals s.Id
                join u in ctx.Users on s.Crtr equals u.Id
                where u.Email == mail
                orderby sl.LikeDate descending
                select new LikeClass { UserName = p.UserName, UserId = p.UserId, PhotoUrl = p.PhotoUrl, OneriId = s.Id, LikeDate = sl.LikeDate }).Take(10).ToList();
            object comments = (from p in ctx.Profiles
                            join sc in ctx.SuggestionComments on p.UserId equals sc.Crtr
                            join s in ctx.Suggestions on sc.SuggestionId equals s.Id
                            join u in ctx.Users on s.Crtr equals u.Id
                            where u.Email == mail
                            orderby sc.Crtm descending
                            select new CommentClass { UserName = p.UserName, UserId = p.UserId, PhotoUrl = p.PhotoUrl, OneriId = s.Id, Crtm = sc.Crtm }).Take(10).ToList();
            object follows = (from u in ctx.Users
                           join f in ctx.Follows on u.Id equals f.FollowerId
                           where f.FollowingId == user_id
                           orderby f.FollowDate descending
                           select new FollowClass { UserName = u.UserName, FollowDate = f.FollowDate, UserId = u.Id, ThumbnailUrl = u.ThumbnailUrl }).Take(10).ToList();
            List myModel = new List();
            myModel.Add(likes);
            myModel.Add(comments);
            myModel.Add(follows);
            return View(myModel);

\n在视图页面上:\n@model IEnumerable\n@{\n ViewBag.Title = \"Index\";\n Layout = \"~/Views/MasterPage/_Layout.cshtml\";\n List list_like = Model.ToList()[0] as List;\n List list_comment = Model.ToList()[1] as List;\n List list_follow = Model.ToList()[2] as List;\n}\n@foreach (var item in list_like)\n{\n

\n

@item.UserName

\n

@item.UserId

\n

@item.PhotoUrl

\n

@item.OneriId

\n

@item.LikeDate

\n

\n

\n}\n
\n@foreach (var item in list_comment)\n{\n

\n

@item.UserName

\n

@item.UserId

\n

@item.PhotoUrl

\n

@item.OneriId

\n

@item.Crtm

\n

\n}\n
\n@foreach (var item in list_follow)\n{\n

\n

@item.UserName

\n

@item.UserId

\n

@item.ThumbnailUrl

\n

@item.FollowDate

\n

\n}\n\n我想在视图页面中显示对象项。但它不起作用,返回空值。请帮忙。\n例如:item.UserName是空引用,但在SQL查询中不是空值。

0