dimanche 9 octobre 2016

Wall full of post and comment in .NET

I have a problem with my small website service. I have to code some Wall with the post and comment from user. I have some model for Post:

 public class Post
{
    public int ID { get; set; }
    public string PostContent { get; set; }
    public DateTime PostDateTime { get; set; }

    public virtual ApplicationUser ApplicationUser { get; set; }
    public virtual ICollection<Comment> Comments { get; set; }
}

and for Comment:

  public class Comment
{
    public int ID { get; set; }
    public string CommentContent { get; set; }
    public DateTime CommentDateTime { get; set; }
    public int PostId { get; set; }

    public virtual ApplicationUser ApplicationUser { get; set; }
    public virtual Post Post { get; set; }
}

I'm using identity model as u can see. My problem is:

1) How i can display all Post + Comment for any Post in the view?

2) Maybe partial view for comment? But how?

3) I have view:

 @foreach (var item1 in Model)
{
    <p>
        <span style="font-weight: bolder">
            @Html.DisplayFor(modelItem => item1.ApplicationUser.UserName)
            Date: @Html.DisplayFor(modelItem => item1.PostDateTime)
        </span>
        <br/>
        @Html.DisplayFor(modelItem => item1.PostContent)
    </p>
}

But that view display only all post without comment. Please help!




Aucun commentaire:

Enregistrer un commentaire