I am developing a simple blog application to teach myself C# and asp .net mvc3. I am stuck at a stage where I need to update comments to a post.
Comment class in my code is as follows:
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; }
}
I have a comment form on the blog details page which takes the name, email and comment. The code is as follow:
<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>
I am not sure how to pass the blogid with this so that the comment gets updated with the correct blogid.
thanks.