开发者

i got an error 'System.Collections.Generic.IEnumerable<EventListing.Models.MyViewModel>' does not contain a definition

开发者 https://www.devze.com 2023-04-10 01:11 出处:网络
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 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:开发者_StackOverflow社区                        <% foreach (var model in Model.Active)
Line 224:                           { %>
Line 225:                        <tr>


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消