[英]Passing partial view as IEnumerable to single model
I'm trying to create a list of items on the create view.我正在尝试在创建视图上创建项目列表。
I'm using VS2017, EF6, MVC5, Code First.我正在使用 VS2017、EF6、MVC5、Code First。
I've got a partial view named _Patients我有一个名为 _Patients 的局部视图
@model IEnumerable<ContosoUniversity.Models.Patient>
<table class="table>">
<thead>
....
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>@Html.DisplayFor(modelItem => item.PatientFirstName)</td>
</tr>
}
</tbody>
</table>
My main view is Create.cshtml我的主要观点是 Create.cshtml
and I'm adding the partial view with我正在添加部分视图
@Html.Partial("_Patients")
My main view is using a single item model我的主要观点是使用单项模型
@model ContosoUniversity.Models.Patient
When I change the main view model to IEnumerable<ContosoUniversity.Models.Patient>
当我将主视图模型更改为IEnumerable<ContosoUniversity.Models.Patient>
the list displays properly but the form fields give me errors because its the wrong type.列表显示正确,但表单字段给我错误,因为它的类型错误。
I'm wanting to just pass the partial view as IEnumerable
, is that possible?我只想将部分视图作为IEnumerable
传递,这可能吗?
尝试通过以下方式加载您的部分
@Html.Partial('_Patients', new List<ContosoUniversity.Models.Patient>())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.