我怎样才能在视图中有这个模型
public class PostDetailsViewModel
{
public Post Posts1 { get; set; }
public IEnumerable<Post> Posts2 { get; set; }
}
看法
@model IEnumerable<forum3.ViewModels.PostDetailsViewModel>
@foreach (var item in Model)
{
<span>@item.Posts1.Title</span><br />
<p>@item.Posts1.Question</p><br /><br />
}
控制器
public ViewResult PostDetails(int id)
{
PostDetailsViewModel postdetailsviewmodel = new PostDetailsViewModel();
postdetailsviewmodel.Posts1 = postRepository.Find(id);
postdetailsviewmodel.Posts2 = postRepository.FindPostByParentIds(id);
List<PostDetailsViewModel> postDetailsList = new List<PostDetailsViewModel>();
postDetailsList.Add(postdetailsviewmodel);
return View(postDetailsList);
}
我如何才能在视图中有 post2 是答案