このトピックに関する多くの質問と回答がありますが、これはうまく動作しません。MVC 5 RenderPageまたはRenderPartialを正常に動作させることができません
私は2つのビューを持っています。 1つは親を表し、もう1つは子レコードを表します。すべてが読み取り専用なので、ビューは非常にシンプルです。ここで
は私の親ビューは次のとおりです。ここで
@model IEnumerable<WebApplication1.vw_CurrentDump>
@{
ViewBag.Title = "CurrentDump";
Layout = "~/Views/Shared/_MyLayout.cshtml";
}
@section head{
<link href="@Url.Content("~/Content/css/style.css")" rel="stylesheet" type="text/css" } />
}
<style>
.headerTest {
text-align: center;
width: 100%;
}
</style>
<h2 class="headerTest">Current Dump</h2>
<table class="aTable">
<tr>
<th>
Dump #
</th>
<th>
Units
</th>
<th>
Start
</th>
<th>
Cars
</th>
<th>
Weight
</th>
<th>
Cars Dumped
</th>
<th>
Tons Dumped
</th>
<th>
Destination
</th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.DumpUnitId)
</td>
<td>
@Html.DisplayFor(modelItem => item.Units)
</td>
<td>
@Html.DisplayFor(modelItem => item.StartTime)
</td>
<td>
@Html.DisplayFor(modelItem => item.Cars)
</td>
<td>
@Html.DisplayFor(modelItem => item.Weight)
</td>
<td>
@Html.DisplayFor(modelItem => item.CarsDumped)
</td>
<td>
@Html.DisplayFor(modelItem => item.TonsDumped)
</td>
<td>
@Html.DisplayFor(modelItem => item.Desintation)
</td>
</tr>
}
</table>
@{ Html.RenderPartial("CurrentDumpCars"); }
は、子レコードのための図である。
@model IEnumerable<WebApplication1.vw_CurrentDumpCars>
@{
Layout = null;
}
<table class="aTable">
<tr>
<th>
Car Number
</th>
<th>
Date Dumped
</th>
<th>
Weight
</th>
<th>
Empty Track
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.CarNumber)
</td>
<td>
@if (item.DateDumped.HasValue)
{
@item.DateDumped.Value.ToString("MM/dd/yyyy HH:mm")
}
</td>
<td>
@Html.DisplayFor(modelItem => item.Weight)
</td>
<td>
@Html.DisplayFor(modelItem => item.EmptyTrackNumber)
</td>
</tr>
}
</table>
(示すように)私は@RenderPageとれるrenderPartialを試してみました。どちらも、同じエラーを返す:
System.InvalidOperationException: 'The model item passed into the dictionary is of type 'System.Collections.Generic.List
1[WebApplication1.vw_CurrentDump]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable
1[WebApplication1.vw_CurrentDumpCars]'.'
それは私がれるrenderPartial方法にvw_CurrentDumpに渡していることを私に言っているように見えるが、それはどんな意味がありません。どちらのビューもEntity Framework 6ライブラリにあります。私が読んだすべては、これがうまくいくはずだと私に伝えます。
ファンタスティック!どうもありがとうございます。私はMVCについて学ぶことがたくさんある。私はあまりにも長い間WPFをやってきました。 RenderActionがトリックを行いました。 –
@ MarkBonafe大歓迎です。 – Ashiquzzaman