MVC2 Paginate Problem, Невозможно найти ссылку - PullRequest
1 голос
/ 28 января 2011

Вот откуда возникла основная проблема, я думал

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

В то время как вот моя ссылка на код Paginate от NerdDinner

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

Он находится в Index of Member

Это помощник, расположенный по адресу (... / 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

Адрес домена, получающего доступ к этой ОШИБКЕ = http://localhost:8219/Member

1 Ответ

1 голос
/ 28 января 2011

PaginatedList появляется в пространстве имен FYP_MVC_SDP_Assignment.Controllers (хотя оно там и не принадлежит), а не в пространстве имен SDP_Assignment.Helpers.PaginatedList, объявленном в представлении.

...