我正在尝试在页面底部创建一个带有评论的博客详细信息页面。我使用我的“发布”模型作为我评论的一些属性和导航列表属性。
我想做的是在页面的最底部创建一个表单来添加新评论。由于我对评论使用了不同的模型,所以我很难弄清楚如何创建这样的场景。
感谢您的任何建议。
编辑 这里有一些代码可以更好地解释:
@model Skuami.Models.PostModel
@{
ViewBag.Title = Model.Title;
}
<div class="blogContentBox">
<div class="blogImage">
<img src="@Model.Image" />
</div>
<div class="blogContent">
<div class="blogDate">@Model.CreateDate</div>
<p class="blogTitle">@Model.Title</p>
@Model.Content
</div>
</div>
<p class="commentTitle">
@Model.Comments.Count @(Model.Comments.Count == 1 ? " comment" : " comments")
</p>
@foreach (var item in Model.Comments)
{
<div class="commentBox">
<p class="commentName">@item.Name</p>
<p class="commentDate">@item.CreateDate</p>
@item.Message
</div>
}
<div class="commentBox">
<p class="commentReply">Leave a Reply</p>
@using (Html.BeginForm("Details", "Home", FormMethod.Post, new { @class = "CommentModel" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<legend></legend>
<div class="editor-label">
@Html.LabelFor(model => model.Comments.Name) <!-- how can I use a 2nd model -->
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Name) <!-- how can I use a 2nd model -->
@Html.ValidationMessageFor(model => model.Name)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Message) <!-- how can I use a 2nd model -->
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Message) <!-- how can I use a 2nd model -->
@Html.ValidationMessageFor(model => model.Message)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
</div>