我正在开发一个简单的博客应用程序来自学C#和asp .net mvc3。我被困在需要更新帖子评论的阶段。
我的代码中的注释类如下:
public class Comment
{
public int CommentID { get; set; }
public string Name { get; set; }
[DataType(DataType.EmailAddress)]
public string Email { get; set; }
[DataType(DataType.MultilineText)]
public string CommentBody { get; set; }
public int BlogID { get; set; }
public virtual Blog Blog { get; set; }
}
我在博客详细信息页面上有一个评论表,其中包含名称,电子邮件和评论。代码如下:
<div class="editor-label">
@Html.LabelFor(model => model.Comment.Name)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Comment.Name)
@Html.ValidationMessageFor(model => model.Comment.Name)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Comment.Email)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Comment.Email)
@Html.ValidationMessageFor(model => model.Comment.Email)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Comment.CommentBody)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Comment.CommentBody)
@Html.ValidationMessageFor(model => model.Comment.CommentBody)
</div>
<p>
<input type="submit" value="Add Comment" />
</p>
我不确定如何使用此传递博客id,以便使用正确的blogid更新评论。
谢谢。
您可以在表单中使用隐藏字段:
@Html.HiddenFor(x => x.Comment.BlogID)
@Html.HiddenFor(model => model.Comment.BlogID)