Html SubscribeVentMapping中Razor语法中的foreach
这就是错误所在。 我正在尝试使用MVC控制器从数据库获取返回视图的数据 错误CS1579 foreach语句无法对“SubscriberEventMapping”类型的变量进行操作,因为“SubscriberEventMapping”不包含“GetEnumerator”的公共实例定义。Html SubscribeVentMapping中Razor语法中的foreach,html,asp.net-mvc,razor,html-helper,Html,Asp.net Mvc,Razor,Html Helper,这就是错误所在。 我正在尝试使用MVC控制器从数据库获取返回视图的数据 错误CS1579 foreach语句无法对“SubscriberEventMapping”类型的变量进行操作,因为“SubscriberEventMapping”不包含“GetEnumerator”的公共实例定义。 @model WebApplicationLPISubscriber.Models.SubscriberEventMapping @using WebApplicationLPISubscriber.Models
@model WebApplicationLPISubscriber.Models.SubscriberEventMapping
@using WebApplicationLPISubscriber.Models;
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.SubscriberID)
</th>
<th>
@Html.DisplayNameFor(model => model.SubscriberID)
</th>
<th>
@Html.DisplayNameFor(model => model.EventTypeName)
</th>
<th>
@Html.DisplayNameFor(model => model.Year)
</th>
<th>
@Html.DisplayNameFor(model => model.CalendarStartDate)
</th>
<th>
@Html.DisplayNameFor(model => model.CalendarEndDate)
</th>
</tr>
</table>
foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.SubscriberID)
</td>
<td>
@Html.DisplayFor(modelItem => item.EventTypeName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Year)
</td>
<td>
@Html.DisplayFor(modelItem => item.CalendarStartDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.CalendarEndDate)
</td>
</tr>
}
@model webapplicationpisubscriber.Models.SubscriberEventMapping
@使用WebApplicationPiSubscriber.Models;
@使用(Html.BeginForm())
{
@Html.AntiForgeryToken()
@DisplayNameFor(model=>model.SubscriberID)
@DisplayNameFor(model=>model.SubscriberID)
@DisplayNameFor(model=>model.EventTypeName)
@Html.DisplayNameFor(model=>model.Year)
@DisplayNameFor(model=>model.CalendarStartDate)
@DisplayNameFor(model=>model.CalendarEndDate)
foreach(模型中的var项目)
{
@DisplayFor(modelItem=>item.SubscriberID)
@DisplayFor(modelItem=>item.EventTypeName)
@DisplayFor(modelItem=>item.Year)
@DisplayFor(modelItem=>item.CalendarStartDate)
@DisplayFor(modelItem=>item.CalendarEndDate)
}
错误发生在foreach中。您的模型声明@model webapplicationpisubscriber.Models.SubscriberEventMapping
不是列表或集合类型。foreach无法循环通过您的模型,因为它不是列表
要使foreach正常工作,请使用List
。请参阅下面的代码
@using WebApplicationLPISubscriber.Models;
@model List<WebApplicationLPISubscriber.Models.SubscriberEventMapping>
@使用WebApplicationPiSubscriber.Models;
@模型列表
您可以在控制器中共享操作吗?