_getProductReviews.cshtml
:
I'm calling my partial view like this:
<p>@Html.Partial("_CreateR");</p>
_CreateR.cshtml
:
This code is auto generated by the controller:
@model Commerce.Domain.Entites.t_review
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>t_review</h4>
<hr />
@Html.ValidationSummary(true)
<div class="form-group">
@Html.LabelFor(model => model.text, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.text)
@Html.ValidationMessageFor(model => model.text)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.title, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.title)
@Html.ValidationMessageFor(model => model.title)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.customer_id, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.customer_id)
@Html.ValidationMessageFor(model => model.customer_id)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.product_fk, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.product_fk)
@Html.ValidationMessageFor(model => model.product_fk)
</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>
}
ProductController
:
// GET: /Product/Create
public ActionResult Create()
{
return View();
}
//
// POST: /Product/Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "id,text,title,customer_id,product_fk")] t_review review)
{
if (ModelState.IsValid)
{
prose.CreateReview(review);
return RedirectToAction("Index");
}
return View(review);
}
When I use a simple view with actionlink it works but when I try to use partial View shows this msg
The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[Commerce.Domain.Entites.t_review]', but this dictionary requires a model item of type 'Commerce.Domain.Entites.t_review'.
_getProductReviews.cshtml
isList<t_review>
and you then pass that to_CreateR.cshtml
whose model ist_review
(notList<t_review>
) – user3559349