@model ******.Models.Comments
@using (Html.BeginForm("CommentForm", "Product", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Comments</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="hide">
<div class="form-group">
@Html.LabelFor(model => model.ProductID, "ProductID", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("ProductID", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.ProductID, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.UserID, "UserID", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("UserID", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.UserID, "", new { @class = "text-danger" })
</div>
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.CommentText, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.CommentText, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CommentText, "", 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>
}
@model ******.Models.Products
@if (User.Identity.IsAuthenticated)
{
Html.RenderPartial("CommentForm");
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult CommentForm(Comments Idea,int id)
{
int userid = database.Users.First(u => u.UserName == User.Identity.Name).UserID;
//var productid = database.Products.Find(id);
if (ModelState.IsValid)
{
Idea.ProductID = id;
Idea.UserID = userid;
Idea.CommentDate = DateTime.Now;
Idea.IsApproved = false;
database.Comments.Add(Idea);
database.SaveChanges();
return View(Idea);
// return View("CommentSubmitSuccess");
}
ViewBag.ProductID = new SelectList(database.Products, "ProductID", "ProductTitle");
ViewBag.UserID = new SelectList(database.Users, "UserID", "UserName");
return View("ShowProduct");
}
برچسب:
نویسنده: خنج