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
我試圖更改爲YP_MVC_SDP_Assignment.Helpers.PaginatedList,但錯誤仍然繼續=。=請幫助...相當急@。@ Thx = D – 1myb 2011-01-28 16:54:37