【发布时间】:2018-04-18 12:13:41
【问题描述】:
有一个表格,其中包含新闻和类别 ID(多对多)。我想推断没有重复的新闻,但 Distinct 方法没有帮助。如何解决问题?
ViewBag.NewsToCategory = db.News_To_Category.Where(db=>db.News.Status == 1).Distinct().ToList();
HTML 代码
@foreach(News_To_Category nw in ViewBag.NewsToCategory)
{
<div class="col-md-4 col-sm-4 hidden-sm">
<div class="blog-home blog-box">
<div class="blog-top-desc">
<div class="blog-date">
@Convert.ToDateTime(nw.News.Dates).ToString("dd MMMM yyyy")
</div>
<h4>@nw.News.Title</h4>
<i class="fa fa-user-o"></i>
<strong>admin</strong>
<i class="fa fa-commenting-o"></i>
<strong>8 comments</strong>
</div>
<img style="min-width:370px;max-width:370px;min-height:240px;max-height:240px" src="~/Uploads/@nw.News.Image">
<div class="blog-btm-desc">
<p>
@nw.News.Content;
</p>
<a href="#" class="btn btn-min btn-solid">
Read More
<i class="fa fa-arrow-right"></i>
</a>
</div>
</div>
</div>
}
【问题讨论】:
-
在News_To_Category表中,有几行具有相同的新闻ID附加到不同的类别,我想只打印该表的新闻,但没有重复,但相同的新闻显示了多次, 不包括 dictinct (), 如何禁用新闻输出
-
不能在 where 子句中包含
NewsCategory吗?
标签: asp.net asp.net-mvc-4 distinct viewbag actionresult