【问题标题】:The model item passed into the dictionary is of type 'System.Collections.Generic.Lis传入字典的模型项的类型为 'System.Collections.Generic.List
【发布时间】:2011-02-14 19:50:31
【问题描述】:

调用索引视图给了我这个非常烦人的错误。谁能告诉我该怎么办

错误: 传入字典的模型项的类型为“System.Collections.Generic.List1[MvcApplication13.Models.Groups]', but this dictionary requires a model item of type 'MvcApplication13.Helpers.PaginatedList1[MvcApplication13.Models.Groups]”。

public ActionResult Index(int?page) { 常量 int pageSize = 10; var group =from p in _db.Groups 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", 新 { page = (Model.PageIndex + 1) }) %>
<p>
    <%= Html.ActionLink("Create New", "Create") %>
</p>

【问题讨论】:

  • 我继承的东西可能有问题?

标签: asp.net asp.net-mvc linq linq-to-entities


【解决方案1】:

粘贴代码时丢失了一些数据。这就是我认为您要粘贴的内容: 查看

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

如果是这样,您的代码应该与此类似(即创建 PaginatedList 类的新实例):

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-16
    • 2014-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-26
    相关资源
    最近更新 更多