_getProductReviews.cshtml
:
私は私の部分的なビューを次のように呼んでいます:
<p>@Html.Partial("_CreateR");</p>
_CreateR.cshtml
:
このコードは、コントローラーによって自動生成されます。
@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);
}
actionlinkでシンプルなビューを使用すると機能しますが、部分的なビューを使用しようとするとこのメッセージが表示されます
ディクショナリに渡されたモデルアイテムのタイプは「System.Collections.Generic.List`1 [Commerce.Domain.Entites.t_review]」ですが、このディクショナリにはタイプ「Commerce.Domain.Entites.t_review」のモデルアイテムが必要です。