2010-05-02 3 views
0

입니다. 호출 색인보기에서이 매우 황당한 오류가 발생합니다. 아무도 말해 줄 수에 대한이사전에 전달 된 모델 항목의 형식은 'System.Collections.Generic.Lis

오류 일 : 가 사전에 전달 된 모델 항목 유형 인 '1[MvcApplication13.Models.Groups]', but this dictionary requires a model item of type 'MvcApplication13.Helpers.PaginatedList 1 MvcApplication13.Models.Groups] System.Collections.Generic.List'.

public ActionResult 색인 (int? page) { const int pageSize = 10; var group = _db.Groups의 p에서부터 orderby p.int_GroupId select p;

 var paginatedGroup = group.Skip((page ?? 0) * pageSize).Take(pageSize).ToList(); 
     return View(paginatedGroup);    
    } 

보기 :

> "%>

지수

<h2>Index</h2> 

<table> 
    <tr> 
     <th></th> 
     <th> 
      int_GroupId 
     </th> 
     <th> 
      vcr_GroupName 
     </th> 
     <th> 
      txt_GroupDescription 
     </th> 
     <th> 
      bit_Is_Deletable 
     </th> 
     <th> 
      bit_Active 
     </th> 
     <th> 
      int_CreatedBy 
     </th> 
     <th> 
      dtm_CreatedDate 
     </th> 
     <th> 
      int_ModifiedBy 
     </th> 
     <th> 
      dtm_ModifiedDate 
     </th> 
    </tr> 

<% foreach (var item in Model) { %> 

    <tr> 
     <td> 
      <%= Html.ActionLink("Edit", "Edit", new { id=item.int_GroupId }) %> | 
      <%= Html.ActionLink("Details", "Details", new { id=item.int_GroupId })%> | 
      <%= Html.ActionLink("Delete", "Delete", new { id=item.int_GroupId })%> 
     </td> 
     <td> 
      <%= Html.Encode(item.int_GroupId) %> 
     </td> 
     <td> 
      <%= Html.Encode(item.vcr_GroupName) %> 
     </td> 
     <td> 
      <%= Html.Encode(item.txt_GroupDescription) %> 
     </td> 
     <td> 
      <%= Html.Encode(item.bit_Is_Deletable) %> 
     </td> 
     <td> 
      <%= Html.Encode(item.bit_Active) %> 
     </td> 
     <td> 
      <%= Html.Encode(item.int_CreatedBy) %> 
     </td> 
     <td> 
      <%= Html.Encode(String.Format("{0:g}", item.dtm_CreatedDate)) %> 
     </td> 
     <td> 
      <%= Html.Encode(item.int_ModifiedBy) %> 
     </td> 
     <td> 
      <%= Html.Encode(String.Format("{0:g}", item.dtm_ModifiedDate)) %> 
     </td> 
    </tr> 

<% } %> 

</table> 
당신이 당신의 코드를 붙여 넣을 때 는 >> ","UpcomingDinners "새 {페이지 = (Model.PageIndex + 1)}) %>
<p> 
    <%= Html.ActionLink("Create New", "Create") %> 
</p> 

+0

내가 상속하는 것에 이상이있을 수 있습니까? – maztt

답변

2

당신은 일부 데이터를 잃었다. 보기 때문에, 당신이 코드는 다음과 유사합니다 경우 (즉, PaginatedList 클래스의 새 인스턴스를 만들 수 있습니다.)

<%@ Page Title="" Language="C#" 
    MasterPageFile="~/Views/Shared/Site.Master" 
Inherits="System.Web.Mvc.ViewPage<MvcApplication13.Helpers.PaginatedList<MvcApplication13.Models.Groups>>" %> 

:

public ActionResult Index(int? page) { 

    const int pageSize = 10; 

    var upcomingDinners = dinnerRepository.FindUpcomingDinners(); 
    var paginatedDinners = new PaginatedList<Dinner>(upcomingDinners, page ?? 0, pageSize); 

    return View(paginatedDinners); 
} 

http://nerddinnerbook.s3.amazonaws.com/Part8.htm를이 내가 붙여 의미 생각입니다

+0

감사합니다. 백만 명이 문제를 해결했습니다. – maztt

관련 문제