我正在尝试建立一个博客网站,如下所示:
类别模型
public class Category
{
public int CategoryID { get; set; }
public String CategoryName { get; set; }
public virtual List<Article> Articles { get; set; }
}
商品模型
public class Article
{
public int Id { get; set; }
public string Header { get; set; }
public string Content { get; set; }
public byte[] BlogImage{ get; set; }
public DateTime? CreationDate{ get; set; }
public int? CategoryID{ get; set; }
public virtual Category Category { get; set; }
}
那么,我该如何在ActionResult函数中发送数据并在image这样的页面中查看博客卡?
public ActionResult Index()
{
using (MvcBlogContext context = new MvcBlogContext())
{
// how to code here?
}
}
<div class="row">
@foreach (var item in Model)
{
<div class="col-md-4">
// how to view category name here?
</div>
}
</div>
<div class="row">
@foreach (var item in Model)
{
<div class="col-md-4">
<div class="post post-widget"
// how to view from 2nd to 4th blog here?
</div>
</div>
}
</div>
您能帮我吗?
答案 0 :(得分:0)
要回答您的一个问题-选择第一个条目,然后选择其余条目
@foreach (var item in Model.Take(1))
第一行,然后
@foreach (var item in Model.Skip(1))
其余。它假定模型中的数据已适当排序。