Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html SubscribeVentMapping中Razor语法中的foreach_Html_Asp.net Mvc_Razor_Html Helper - Fatal编程技术网

Html SubscribeVentMapping中Razor语法中的foreach

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

这就是错误所在。 我正在尝试使用MVC控制器从数据库获取返回视图的数据

错误CS1579 foreach语句无法对“SubscriberEventMapping”类型的变量进行操作,因为“SubscriberEventMapping”不包含“GetEnumerator”的公共实例定义。

@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;
@模型列表
您可以在控制器中共享操作吗?