I have blog model with public ICollection<Comment> Comments { get; set; } and comment model. I have created view for article (Details view) and I want to show everything from model blog (not problem) and comments to article to and after comments then show form for adding comment to blog (not in other page, I want it in the view with blog).
public class BlogPost
{
public int BlogPostID { get; set; }
public string Title { get; set; }
public string Body { get; set; }
public ICollection<Comments>Comments {get;set;}
}
public class Comments
{
public int BlogPostID { get; set; }
public string Comment { get; set; }
public DateTime dateTime { get; set; }
public virtual BlogPost BlogPost { get; set; }
}
View
@model projectMvc.Model.BlogPost;
<div>
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => mode.Title)
</dt>
<dd>
@Html.DisplayFor(model => model.Title)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Body )
</dt>
<dd>
@Html.DisplayFor(model => model.Movie.Body )
</dd
</dl>
</div>
@if (Model.Comments != null)
{
foreach (var comment in Model.Comments)
{
@Html.Partial("_Comment", comment)
}
}
It shows the blog data and there is partial view for all comments to blog. And now I am not sure how to add form for adding comments. Thank you.