2011-01-28 39 views
1

这是塔最主要的问题来自我认为MVC2分页问题,​​无法找到参考

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

虽然这里是从NerdDinner范例

我分页代码参考
<% if (Model.HasPreviousPage) { %> 
    <%: Html.RouteLink("<<<", 
         "Member", 
         new {Page=Model.pageindex -1}) %> 
<% } %> 
<% if(Model.HasNextPage) { %> 
<%: Html.RouteLink(">>>", 
       "Member", 
       new {Page =Model.PageIndex +1})%> 
<% } %> 

它位于会员

指数

这是帮助者位于(.../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的解决方案,但仍然难以解决...任何人都可以帮助我出来s,而我需要赶分配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 

域地址访问此错误= http://localhost:8219/Member

回答

1

PaginatedList apears是在FYP_MVC_SDP_Assignment.Controllers namesoace(虽然它不属于那里),而不是在视图中声明的SDP_Assignment.Helpers.PaginatedList名称空间中。

+0

我试图更改为YP_MVC_SDP_Assignment.Helpers.PaginatedList,但错误仍然继续=。=请帮助...相当急@。@ Thx = D – 1myb 2011-01-28 16:54:37