سلام دوستان
من میخوام کاربران بتونن درباره محصولاتی که نمایش داده میشه نظر بدن.برای این کار یک partailview ایجاد کردم که از جدول کامنت مدلش رو میگیره و از نوع create هست.بعد با استفاده از html.renderpartail اون رو داخل view ای که محصولات رو نمایش میده فراخوانی کردم ولی مشکلم اینجاست که میخوام همزمان با فراخوانی partailview آی دی مربوط به اون محصول رو هم پاس بدم به actionresult داخل کنترلر. راهی هست برای انجام این کار؟ اگر نه فرم نظردهی رو از چه طریق دیگه ای قرار بدم؟
این partialview من هست
@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>
}
اینم بخشی از ShowProductView هست که توش partailview را فراخوانی میکنم
@model ******.Models.Products
@if (User.Identity.IsAuthenticated)
{
Html.RenderPartial("CommentForm");
}
اینم کنترلر من هست
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult CommentForm(Comments comments,int id)
{
int userid = database.Users.First(u => u.UserName == User.Identity.Name).UserID;
//var productid = database.Products.Find(id);
if (ModelState.IsValid)
{
comments.ProductID = id;
comments.UserID = userid;
comments.CommentDate = DateTime.Now;
comments.IsApproved = false;
database.Comments.Add(comments);
database.SaveChanges();
return View(comments);
// return View("CommentSubmitSuccess");
}
ViewBag.ProductID = new SelectList(database.Products, "ProductID", "ProductTitle");
ViewBag.UserID = new SelectList(database.Users, "UserID", "UserName");
return View("ShowProduct");
}