MVC2 Paginate问题,找不到参考

时间:2011-01-28 09:03:10

标签: c# asp.net-mvc pagination

这是我想到的主要问题

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

虽然这是来自NerdDinner的我的Paginate Code参考

    <% if (Model.HasPreviousPage) { %>
    <%: Html.RouteLink("<<<",
                        "Member",
                        new {Page=Model.pageindex -1}) %>
<% } %>
<% if(Model.HasNextPage) { %>
<%: Html.RouteLink(">>>",
               "Member",
               new {Page =Model.PageIndex +1})%>
<% } %>

它位于会员索引

这是Helper位于(... / Helpers / PaginateList.cs)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FYP_MVC_SDP_Assignment.Models;
using System.ComponentModel.DataAnnotations;

namespace FYP_MVC_SDP_Assignment.Controllers
{
public class PaginatedList<T> : List<T>
{
public int PageIndex { get; private set; }
public int PageSize { get; private set; }
public int TotalCount { get; private set; }
public int TotalPages { get; private set; }

public PaginatedList(IQueryable<T> source, int pageIndex, int pageSize)
{
    PageIndex = pageIndex;
    PageSize = pageSize;
    TotalCount = source.Count();
    TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize);
    this.AddRange(source.Skip(PageIndex * PageSize).Take(PageSize));
}

public bool HasPreviousPage
{
    get
    {
        return (PageIndex > 0);
    }
}

public bool HasNextPage
{
    get
    {
        return (PageIndex + 1 < TotalPages);
    }
}

}  }

这是我的会员索引控制器

        public ActionResult Index(int page=0)
    {
        const int pageSize = 8;
        var members = clubmemberrepository.FindAllMember();
        var paginatedMember = new PaginatedList<tblMember> (members,
            page,
            pageSize);
        return View(paginatedMember);
    }

这是我的路线

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace FYP_MVC_SDP_Assignment
{
// Note: For instructions on enabling IIS6 or IIS7 classic mode, 
// visit http://go.microsoft.com/?LinkId=9394801

public class MvcApplication : System.Web.HttpApplication
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Member",
            "Member/page/{page}",
            new {controller = "Member", action ="Index"}
        );

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional }         // Parameter defaults
        );                                                                                                 

    }

    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();

        RegisterRoutes(RouteTable.Routes);
    }
}

}

虽然这是错误,我一直在尝试通过stackoverflow解决方案,但仍然无法解决......任何人都可以帮助我解决这个问题,而我需要急于分配XD

错误...

Server Error in '/' Application.

Compilation 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: CS0234: The type or namespace name 'Helpers' does not exist in the namespace 'FYP_MVC_SDP_Assignment' (are you missing an assembly reference?)

Source Error:


Line 170:    
Line 171:    [System.Runtime.CompilerServices.CompilerGlobalScopeAttribute()]
Line 172:    public class views_member_index_aspx :    System.Web.Mvc.ViewPage<FYP_MVC_SDP_Assignment.Helpers.PaginatedList<Member>>, System.Web.SessionState.IRequiresSessionState, System.Web.IHttpHandler {
Line 173:        
Line 174:        private static bool @__initialized;

Source File: c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\eeab298d\fa291c0d\App_Web_index.aspx.7979c542.cpekphek.0.cs    Line: 172

访问此ERROR的域地址= http://localhost:8219/Member

1 个答案:

答案 0 :(得分:1)

PaginatedList似乎位于FYP_MVC_SDP_Assignment.Controllers命名空间中(虽然它不属于那里),而不是视图中声明的SDP_Assignment.Helpers.PaginatedList命名空间。

相关问题