1
I am working on a project to learn ASP.NET MVC and Razor. Right now I have a model of post
with a view, and a view associated with model class comment to create a new comment. I wanted to know how to put the view creation of commentary at the end of the post, and when to submit as associate the comment to the post (I have a variable PostId
in the comment template to make the association). I manually entered some comments in the database and they appear in the right place because I put the PostId
manually, which is not functional. See the view to create a comment:
@model shanuMVCUserRoles.CommentSet
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>CommentSet</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.MemberID, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.MemberID, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.MemberID, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.PostID, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.PostID, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.PostID, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Content, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Content, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Content, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@Html.Partial("_Additionrcomment", new Commentset { Postid = Model.Postid, Memberid = User.Identity.Getuserid() }) only this line has helped me more than what I found before, very good the answer!
– ihavenokia