Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Professional ASP.NET MVC 3
BOOK: Professional ASP.NET MVC 3
This is the forum to discuss the Wrox book Professional ASP.NET MVC 3 by Jon Galloway, Phil Haack, Brad Wilson, K. Scott Allen; ISBN: 978-1-1180-7658-3
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET MVC 3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old July 16th, 2012, 05:13 AM
Registered User
Join Date: Jul 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Confusing to follow code in Chapter 3 (Views)

I'm finding it quite difficult to follow the code samples in Chapter 3 (Views).

I can see that NuGet has installed a Samples folder, but the samples dont work.

When I run http://localhost:6715/Albums/ListStronglyTyped, I get:

The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[MvcMusicStore.Controllers.Album]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[MvcMusicStore.Models.Album]'.

When I run http://localhost:6715/Albums/ListWeaklyTyped
I get errors on Line 4 below:

Object reference not set to an instance of an object.

Line 2:
Line 3: <ul>
Line 4: @foreach(Album p in (ViewBag.Albums as IEnumerable<Album>)) {
Line 5: <li>@p.Title</li>
Line 6: }

Help !!!

Last edited by gjok; July 16th, 2012 at 05:38 AM..
Old February 21st, 2013, 08:51 AM
Registered User
Join Date: Feb 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

You should use the following line on top of your View

@model IEnumerable<YourApp.Models.Albums>

Last edited by karthikreddy509; February 21st, 2013 at 08:59 AM..

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 3 - Dynamic Views teamstar BOOK: Beginning iOS 5 Application Development 2 March 11th, 2012 11:12 AM
Confusing XPath chapter!!! skystar3 BOOK: Beginning XML, 4th Ed ISBN: 978-0-470-11487-2 2 December 8th, 2010 08:29 PM
Chapter 2 Unable to follow instructions GarethHowell BOOK: Professional SharePoint 2007 Development ISBN: 978-0-470-11756-9 4 July 9th, 2008 03:49 AM
Chapter 4 - Two Views, not working for me... bigtalk BOOK: Beginning Ruby on Rails 1 January 3rd, 2008 07:30 AM
deployment chapter hard to follow robert BOOK: ASP.NET Website Programming Problem-Design-Solution 3 June 20th, 2003 12:22 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.