Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Professional ASP.NET MVC 2
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional ASP.NET MVC 2
This is the forum to discuss the Wrox book Professional ASP.NET MVC 2 by Jon Galloway, Scott Hanselman, Phil Haack, Scott Guthrie, Rob Conery; ISBN: Professional ASP.NET MVC 2
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET MVC 2 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 3rd, 2011, 02:26 PM
Authorized User
 
Join Date: Dec 2010
Posts: 22
Thanks: 10
Thanked 0 Times in 0 Posts
Default Page 106,7; Adding Pagination

After adding the code for pages 106 and 107, I am getting this error when displaying the /Dinners URL:


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: CS0246: The type or namespace name 'Dinner' could not be found (are you missing a using directive or an assembly reference?)

Source Error:



Line 170:
Line 171: [System.Runtime.CompilerServices.CompilerGlobalScop eAttribute()]
Line 172: public class views_dinners_index_aspx : System.Web.Mvc.ViewPage<NerdDinner.Helpers.Paginat edList<Dinner>>, System.Web.SessionState.IRequiresSessionState, System.Web.IHttpHandler {
Line 173:
Line 174: private static bool @__initialized;


Source File: c:\Users\Knute\AppData\Local\Temp\Temporary ASP.NET Files\root\655b8610\3cbe4a13\App_Web_index.aspx.32 d6c807.kimgmkgd.0.cs Line: 172

-------------------------

Page 106 says to add a class called PaginatedList<T> but it doesn't say where to put it. Based on what was said in page 107 I put it in the Helpers folder. This is a new folder I created in the NerdDinner project.

Here is PaginatedList<T>:

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace NerdDinner.Helpers
{
    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);
            }
        }
    }
}
As per page 107 I changed the GET: /Dinners/ method in DinnersController: (I had to add
Code:
using NerdDinner.Helpers;
to get it to work.

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NerdDinner.Models;
using NerdDinner.Helpers;

namespace NerdDinner.Controllers
{
    public class DinnersController : Controller
    {
        DinnerRepository dinnerRepository = new DinnerRepository();

        //
        // GET: /Dinners/
        //      /Dinners/Page/2

        public ActionResult Index(int page = 0)
        {
            const int pageSize = 10;

            var upcomingDinners = dinnerRepository.FindUpcomingDinners();
            var paginatedDinners = new PaginatedList<Dinner>(upcomingDinners, page, pageSize);

            return View(paginatedDinners);
        }
...
Then I changed \Views\Dinners\Index.aspx as per page 107:

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

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Index
</asp:Content>

<asp:Content ID="Main" ContentPlaceHolderID="MainContent" runat="server">

    <h2>UpComming Dinners</h2>

    <ul>
        <% foreach (var dinner in Model) { %>
            <li>
                <%: Html.ActionLink(dinner.Title, "Details", new { id=dinner.DinnerID }) %>
                on
                <%: dinner.EventDate.ToShortDateString() %>
                @
                <%: dinner.EventDate.ToShortTimeString() %>
            </li>
        <% } %>
    </ul>

    <% if (Model.HasPreviousPage)
       { %>
            <%: Html.RouteLink("<<<", "UpcomingDinners", new { page = (Model.PageIndex - 1) })%>
    <% } %>

    <% if (Model.HasNextPage)
       { %>
            <%: Html.RouteLink(">>>", "UpcomingDinners", new { page = (Model.PageIndex + 1) })%>
    <% } %>

</asp:Content>
Any help would be appreciated. Thanks.

--
Knute
  #2 (permalink)  
Old March 3rd, 2011, 02:55 PM
Friend of Wrox
Points: 539, Level: 8
Points: 539, Level: 8 Points: 539, Level: 8 Points: 539, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2010
Location: Seattle
Posts: 106
Thanks: 1
Thanked 17 Times in 17 Posts
Default

Need full namespace for Dinner.

<%@ Page Inherits="System.Web.Mvc.ViewPage<NerdDinner.Helpe rs.PaginatedList<NerdDinner.Models.Dinner>>" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" %>
The Following User Says Thank You to flyinhawaiian For This Useful Post:
ksnortum (March 3rd, 2011)
  #3 (permalink)  
Old March 3rd, 2011, 03:01 PM
Authorized User
 
Join Date: Dec 2010
Posts: 22
Thanks: 10
Thanked 0 Times in 0 Posts
Default

Thanks, that was it!
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding a content page... DavidTaylor BOOK: Beginning ASP.NET 4 : in C# and VB 1 July 3rd, 2010 03:47 PM
Chap 2 forums, pagination issues page 55-56 kenj BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9 0 October 19th, 2009 10:28 PM
adding another page? kwikwisi .NET Framework 2.0 1 April 21st, 2008 04:31 AM
Adding new table on page dungey Javascript 2 February 20th, 2004 07:11 AM



All times are GMT -4. The time now is 10:42 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.