2011-09-29 91 views
1

如何傳遞多個模型控制器和數據綁定到的ViewPage我得到一個錯誤「System.Collections.Generic.IEnumerable <EventListing.Models.MyViewModel>」不包含一個定義

我有列表頁在該頁面中包含兩個選項卡,一個用於活動列表,另一個用於活動列表。

如何創建模型並將數據綁定到查看頁面。

我如何將數據綁定到瀏覽網頁,我使用強類型模型

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> 

回答

2

您的ViewPage代碼與您發佈的錯誤消息不匹配。

ViewPage代碼顯示您正在傳遞的模型是您正在循環顯示鏈接的MyViewModel的集合。

錯誤消息說您只傳遞一個MyViewModel,並且您想循環訪問Active集合。

讓你在使用

@model MyViewModel 

代替

@model IEnumerable<MyVieWModel> 
+0

感謝man.it工程更改您的ViewPage。 – Sathish

相關問題