سوال: پاس دادن پارامتر به partialview ای که داخل یک view دیگر هست به کنترلر

ساخت وبلاگ

سلام دوستان
من میخوام کاربران بتونن درباره محصولاتی که نمایش داده میشه نظر بدن.برای این کار یک 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 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");
}
برنامه نویس...
ما را در سایت برنامه نویس دنبال می کنید

برچسب : نویسنده : محمد رضا جوادیان programers بازدید : 237 تاريخ : يکشنبه 24 دی 1396 ساعت: 19:44