私は2つの部分的なビューを含むビューを持っています。MVC、標準パーシャルビュー、リストパーシャルビュー。一緒に働いていない! S.O.S. xD
@model ListViewModel
....
@{
Html.RenderPartial("EditCartItemsPartical");
Html.RenderPartial("ShowProductINFO", Model.Products);
}
と私はちょうど最初の部分とfromを作成し、2番目の部分のリストを作成したいと思います。
部分図
EditCartItemsPartical.cshtml
@model TestNewATM3._0.Models.CartItem
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<div class="form-group">
@Html.LabelFor(model => model.CartId, "CartId", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.CartId, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CartId, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ProductId, "ProductId", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ProductId, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ProductId, "", new { @class = "text-danger" })
</div>
</div>
.... // more control for CartItem
<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>
}
ShowProductINFO.cshtml
@model IEnumerable<TestNewATM3._0.Models.AllProduct2>
<p>@Html.ActionLink("Create New", "Create")</p>
<table class="table">
<tr>
<th>ID</th>
<th>@Html.DisplayNameFor(model => model.Title)</th>
</tr>
@foreach (var item in Model) {
<tr>
<td>@Html.DisplayFor(model => item.Id)</td>
<td>@Html.DisplayFor(modelItem => item.Title)</td>
</tr>
}
</table>
そして、私のコントローラで、私はこれを得ました。
public ActionResult Edit()
{
var db = ApplicationDbContext.Create();
var list = new ListViewModel
{
Products = db.AllProduct2s.ToList(),
Users = db.Users.ToList(),
Cart = db.Carts.ToList(),
CartItem = db.CartItems.ToList()
};
return View(list);
}
しかし、問題は、私は私の見解でlist
を送信する場合、その後、私の最初の部分は、それが@model TestNewATM3.0.Models.CartItem
をしたい原因の問題を取得するので、私は同時に両方の部分を示して傾けることです。しかし私がリストを送っていなければ私はそれを送らないので私のリストは表示されません。
どのようにして、通常の部分フォームビューとリスト部分ビューを同時に表示するには?
'Html.RenderPartial(" EditCartItemsPartical "、新しいCartItem());'(部分ビューに 'CartItem'の新しいインスタンスを渡します)。 –
[この質問/回答](http://stackoverflow.com/questions/40373595/the-model-item-passed-into-the-dictionary-is-of-type-but-this-dictionary)を読んでみてください。 -requ)あなたが得たと思われるエラーの説明を(たとえあなたがあなたの質問に含めなかったとしても) –
私はそれを見ていただきありがとうございます –