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
| 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 Search this Thread Display Modes
  #1 (permalink)  
Old December 20th, 2010, 04:37 AM
Registered User
 
Join Date: Dec 2010
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
Default Paginated List (Helpers) error

Code:
Inherits="System.Web.Mvc.ViewPage<NerdDinner.Helpers.PaginatedList<NerdDinner.Models.Dinner>>"
...returns the following error for me.
The type or namespace name 'Helpers' does not exist in the namespace 'NerdDinner' (are you missing an assembly reference?)



also the "foreach" in the following statement:
Code:
<% foreach (var dinner in Model) { %>
returns the following error:
foreach statement cannot operate on variables of type 'NerdDinner.Helpers.PaginatedList<NerdDinner.Model s.Dinner>' because 'NerdDinner.Helpers.PaginatedList<NerdDinner.Model s.Dinner>' does not contain a public definition for 'GetEnumerator'


When I got to the section in the book on Paginated List's (p103-108), the book mentioned 'Helper' but gives absolutely no background on what it is. I've searched and searched looking through the book and online, tried countless fixes and I can't seem to figure out why when I click on the "Find Dinner" link on my NerdDinner application I'm receiving the above noted errors.
  #2 (permalink)  
Old December 21st, 2010, 03:48 AM
Registered User
 
Join Date: Dec 2010
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
Default further...

in the following 'Inherits'
Code:
Inherits="System.Web.Mvc.ViewPage<NerdDinner.Helpers.PaginatedList<NerdDinner.Models.Dinner>>"
"NerdDinner.Helper..." is the name of the site/project/solution.

"NerdDinner.Helpers.Paginat..." is a folder in the solution.

"...Helpers.PaginatedList" is a .cs 'class' in the folder.


What is the correct way to use Paginated Lists as shown in the first section of the book. Please help.
  #3 (permalink)  
Old December 21st, 2010, 04:00 AM
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

Can you post the code for the Dinner model? Check to see if properties are public.
  #4 (permalink)  
Old December 21st, 2010, 04:04 AM
Registered User
 
Join Date: Dec 2010
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
Default

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

namespace NerdDinner.Models
{
    [Bind(Include="Title,Description,EventDate,Address,Country,ContactPhone,Latitude,Longitude")]
    [MetadataType(typeof(Dinner_Validation))]
    public partial class Dinner
    {
        //...
    }
    public class Dinner_Validation
    {
        [Required(ErrorMessage = "Title is required")]
        [StringLength(50, ErrorMessage = "Title may not be longer than 50 characters")]
        public string Title { get; set; }

        [Required(ErrorMessage = "Description is required")]
        [StringLength(265, ErrorMessage = "Description must be 256 characters or less")]
        public string Description { get; set; }

        [Required(ErrorMessage = "Address is required")]
        public string Address { get; set; }

        [Required(ErrorMessage = "Country is required")]
        public string Country { get; set; }

        [Required(ErrorMessage = "Phone# is required")]
        public string ContactPhone { get; set; }
    }
}
  #5 (permalink)  
Old December 21st, 2010, 06:31 AM
Registered User
 
Join Date: Dec 2010
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
Default Answer!

System.Web.Mvc.ViewPage<NerdDinner.Models.PaginatedList<NerdDinner.Models.Dinner>>
  #6 (permalink)  
Old February 1st, 2011, 01:13 AM
Registered User
 
Join Date: Jan 2011
Posts: 4
Thanks: 0
Thanked 1 Time in 1 Post
Default Possible Solution

Quote:
Originally Posted by Mr. Bill View Post
in the following 'Inherits'
Code:
Inherits="System.Web.Mvc.ViewPage<NerdDinner.Helpers.PaginatedList<NerdDinner.Models.Dinner>>"
"NerdDinner.Helper..." is the name of the site/project/solution.

"NerdDinner.Helpers.Paginat..." is a folder in the solution.

"...Helpers.PaginatedList" is a .cs 'class' in the folder.


What is the correct way to use Paginated Lists as shown in the first section of the book. Please help.
Bill...
I have a problem within thew same chunk of code.
I have tried several ways, and although my solution compiles perfectly, when I invoke the index action method by sending a GET request in the browser (http://localhost:1799/Dinners) I get a " Server Error in '/' Application. ".

The way I see (and try to deduce) the code is:

"Helpers" is a namespace within the "NerdDinner" namespace.
So I created the "Helpers" namespace and I created the PaginatedList class within PaginatedList.cs file inside the Helpers namespace:

namespace NerdDinner.Helpers
{
public class PaginatedList<T> : List<T>
{
//--- Propiedades ---//
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 bool HasPreviousPage
{
get
{
return ( PageIndex > 0 );
}
}

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

//--- Methods ---//

public PaginatedList(IQueryable<T> fuente,
int indicePagina,
int tamanoPagina)
{
PageIndex = indicePagina;
PageSize = tamanoPagina;

//--- Query 1 ---//
TotalCount = fuente.Count( );

TotalPages = (int)Math.Ceiling( TotalCount / (double)PageSize );

//--- Query 2 ---//
this.AddRange( fuente.Skip( PageIndex * PageSize ).Take( PageSize ) );
}

}
}

Now it is up to you to create a folder called Helpers and include the Helpers namespace inside that folder.

Hope it helps in someway.
Carlos
  #7 (permalink)  
Old March 4th, 2011, 06:25 AM
Registered User
 
Join Date: Dec 2010
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
Default Carlos' bleh blah blu bleh blah blah blah blah blah

December 20th, 2010, 04:37 AM
↑ date thread created.

↓ date of you're response.
Good Ol' February 1st, 2011, 01:13 AM
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Html helpers doesn't work on site.master Gabor66 BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950 1 November 4th, 2009 11:29 AM
Generic List error ferahl C# 2 October 30th, 2007 03:28 AM
Why Countries in Helpers? plb BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 February 22nd, 2007 07:14 PM
Error in Drop Down List anbane80 ASP.NET 1.0 and 1.1 Basics 3 December 13th, 2006 03:21 AM
List Box Error zoltac007 Visual Basic 2005 Basics 0 June 5th, 2006 12:56 PM



All times are GMT -4. The time now is 05:16 AM.


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