我收到错误“System.Collections.Generic.IEnumerable”不包含定义

发布于 2024-12-07 09:31:04 字数 1832 浏览 0 评论 0原文

我如何将多个模型传递给控制器​​并将数据绑定到视图

页面我有列表页面,该页面包含两个选项卡,一个用于活动列表,另一个用于活动列表。

我如何创建模型并将数据绑定到视图页面。

我如何将数据绑定到视图页面,我使用强类型模型

public class EventInfo  
    {

        public string SUBSITE { get; set; }
        public string TITLE { get; set; }
------
}
public class MyViewModel
{
    public IEnumerable<SomeViewModel> Active { get; set; }
    public IEnumerable<SomeViewModel> InActive { get; set; }
}



var model = new MyViewModel
            {
                Active = EventModel.EventList(ids, "", "", "", "", "", "", "", "1", "").ToList(),
                InActive = EventModel.EventList(ids, "", "", "", "", "", "", "", "1", "1").ToList()
            };

这是我的视图页面代码

<% foreach (var model in Model)
   { %>
     <tr>
       <td>
          <%= Html.ActionLink(model.TITLE, "Detail", new { id = model.EVENT_ID })%>
        </td>

我收到错误

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS1061: 'System.Collections.Generic.IEnumerable<EventListing.Models.MyViewModel>' does not contain a definition for 'Active' and no extension method 'Active' accepting a first argument of type 'System.Collections.Generic.IEnumerable<EventListing.Models.MyViewModel>' could be found (are you missing a using directive or an assembly reference?)

Source Error:



Line 221:                    </thead>
Line 222:                    <tbody>
Line 223:                        <% foreach (var model in Model.Active)
Line 224:                           { %>
Line 225:                        <tr>

how can i Pass multiple model to controller and bind the data to viewpage

i have list page in that page contains two tabs, one for active list and another one In active list.

how can i create a model and bind the data to viewpage.

how can i bind the data to view page, i used strong typed model

public class EventInfo  
    {

        public string SUBSITE { get; set; }
        public string TITLE { get; set; }
------
}
public class MyViewModel
{
    public IEnumerable<SomeViewModel> Active { get; set; }
    public IEnumerable<SomeViewModel> InActive { get; set; }
}



var model = new MyViewModel
            {
                Active = EventModel.EventList(ids, "", "", "", "", "", "", "", "1", "").ToList(),
                InActive = EventModel.EventList(ids, "", "", "", "", "", "", "", "1", "1").ToList()
            };

this is my view page code

<% foreach (var model in Model)
   { %>
     <tr>
       <td>
          <%= Html.ActionLink(model.TITLE, "Detail", new { id = model.EVENT_ID })%>
        </td>

I got an error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS1061: 'System.Collections.Generic.IEnumerable<EventListing.Models.MyViewModel>' does not contain a definition for 'Active' and no extension method 'Active' accepting a first argument of type 'System.Collections.Generic.IEnumerable<EventListing.Models.MyViewModel>' could be found (are you missing a using directive or an assembly reference?)

Source Error:



Line 221:                    </thead>
Line 222:                    <tbody>
Line 223:                        <% foreach (var model in Model.Active)
Line 224:                           { %>
Line 225:                        <tr>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绮筵 2024-12-14 09:31:04

您的 ViewPage 代码与您发布的错误消息不匹配。

ViewPage 代码显示您传递的模型是您循环以显示链接的 MyViewModel 的集合。

错误消息表明您仅传递一个 MyViewModel 并且您想要循环访问 Active 集合。

更改您的 ViewPage,以便您使用

@model MyViewModel

而不是

@model IEnumerable<MyVieWModel>

Your ViewPage code does not match up with the error message you posted.

The ViewPage code shows that the Model you're passing is a collection of MyViewModel that you're looping through to display links.

The error message says that you're only passing a single MyViewModel and you want to loop through the Active collection.

Change your ViewPage so you're using

@model MyViewModel

instead of

@model IEnumerable<MyVieWModel>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文