Create a new partial view, make it a strongly typed one of the type comments.
From the scaffolding templates, select the Create template.
handle normal add a new comment script.
Add this partial view to the article details page.
Please note that when you are going to save a new comment, you will need to get the ID of the hosting article.
Hopefully now it is clear, if not, let me know.
update: by assuming that you add a partial "AddComment" view to the "Article Details" view, you can do the following to add a comment.
1- Change the GET (Create) action inside CommentController as follows:
public ActionResult Create(int articleID) { var newComment = new CommentEntity(); newComment.articleID = articleID;
1- perform the POST action (Create) as follows:
[HttpPost] public ActionResult Create(Comment commentEntity) {
2- A partial view of the comment will look something like this:
@model NGO.Models.Comment @using (Html.BeginForm()) { @Html.ValidationSummary(true) <div class="addcommentbox"> <h2> Add Comment </h2> @Html.TextAreaFor(model => model.Description) <div class="ErrorMessage"> @Html.ValidationMessageFor(model => model.Description) </div> <input id="addComment" type="button" onclick="" value="Add" /> </div> }
3 on the ArticleDetails page in the right place where you need the comment section to show, use the RenderAction method to render the AddComment Partial view as follows:
Html.RenderAction("Create", "Comment",new {articleID = Model.ID});
the previous line will call the GET (Create) action inside CommentColtroller and pass the current article identifier, so the already filled in current article identifier will appear in the AddComment Partial view (and this is what we want).
so that he does not hesitate to ask me if he is not yet clear, and let me know if this works for you.