p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional ASP.NET MVC 2 (http://p2p.wrox.com/forumdisplay.php?f=588)
-   -   NerdDinner ViewModel Errata (http://p2p.wrox.com/showthread.php?t=80173)

Darthus July 18th, 2010 12:39 AM

NerdDinner ViewModel Errata
 
Hey guys,

Noticed some errata in the ViewModel section. I figured I would post it here so other users could see it if they get stuck. Seemed pretty big and had me stuck for a while, so wanted to share.

First, on page 88, it tells you to create a DinnerFormViewModel class, but doesn't say where, the namespace, usings etc. It appeared to be a model, as it uses the Dinner class. So I put it there and made it part of that namespace. I confirmed this is how it is in the NerdDinner 2.0 download zip as well.

However, on page 89 it says to update the inheret tag on your edit page to: Inherits=”System.Web.Mvc.ViewPage<NerdDinner.Con trollers.DinnerFormViewModel>

So... I think that's wrong, should be Models, not controllers.

That's a smaller one, the big one that stuck me was Code snippet 1-52 on the bottom of page 89 start of page 90. It tells you to update your view code for your edit page, but aside from changing the SelectFor tag to consume the new Country SelectList, it doesn't have any of the other number of updates you need to do.

Since you're using the ViewModel now, you need to have everything else use m.Dinner.(property). This also needs to be done to the Create page as well of course, (though you combine them in the next section).

Hope this helps someone.

hjbaard July 18th, 2010 07:52 AM

Quote:

Originally Posted by Darthus (Post 260504)
Hey guys,

Noticed some errata in the ViewModel section. I figured I would post it here so other users could see it if they get stuck. Seemed pretty big and had me stuck for a while, so wanted to share.

First, on page 88, it tells you to create a DinnerFormViewModel class, but doesn't say where, the namespace, usings etc. It appeared to be a model, as it uses the Dinner class. So I put it there and made it part of that namespace. I confirmed this is how it is in the NerdDinner 2.0 download zip as well.

However, on page 89 it says to update the inheret tag on your edit page to: Inherits=”System.Web.Mvc.ViewPage<NerdDinner.Con trollers.DinnerFormViewModel>

So... I think that's wrong, should be Models, not controllers.

That's a smaller one, the big one that stuck me was Code snippet 1-52 on the bottom of page 89 start of page 90. It tells you to update your view code for your edit page, but aside from changing the SelectFor tag to consume the new Country SelectList, it doesn't have any of the other number of updates you need to do.

Since you're using the ViewModel now, you need to have everything else use m.Dinner.(property). This also needs to be done to the Create page as well of course, (though you combine them in the next section).

Hope this helps someone.

That is not the only thing you have te change.
To make it work you also have to change the POST Edit method in the controller to let the controller save the changes.

The TryUpdateModel(dinner) will not work anymore because the form values it get are Dinner.Tittle in stead of Tittle.
To fix this you have to add a prefix to the TryUpdateModel (overloaded)

Like this:

[HttpPost]
public ActionResult Edit(int id, FormCollection formValues)
{

Dinner dinner = dinnerRepository.GetDinner(id);
if (TryUpdateModel(dinner, "Dinner"))
{
......
}

Darthus July 18th, 2010 10:38 PM

Thanks for the addition.

Just to add to this it looks it continues with the AJAX map starting on page 127. All the Javascript references the controls by names like "Address" and "Latitude", when they should be "Dinner_Address" and "Dinner_Latitude". The online NerdDinner source code reflects this, but the javascript in the book doesn't.

Additionally, the Site.css needs to be updated in order for the map to position and display correctly, but this isn't mentioned at all in the book. I just copied over the .css from the NerdDinner source.

hjbaard July 19th, 2010 01:52 AM

Quote:

Originally Posted by Darthus (Post 260535)
Thanks for the addition.

Just to add to this it looks it continues with the AJAX map starting on page 127. All the Javascript references the controls by names like "Address" and "Latitude", when they should be "Dinner_Address" and "Dinner_Latitude". The online NerdDinner source code reflects this, but the javascript in the book doesn't.

Additionally, the Site.css needs to be updated in order for the map to position and display correctly, but this isn't mentioned at all in the book. I just copied over the .css from the NerdDinner source.

Looks like they have some editing to do on the book [:)]

marciohiroyuki July 29th, 2010 12:33 AM

I have the same problem that you, Darthus. Did Wrox publish a errata about this?

jlakes August 4th, 2010 01:07 PM

The book is full of errors!
 
I've been hunkered down with this book for the last two weeks. It's been a good overview, but the examples are full of errors and this has caused me a lot of aggravation! I would expect the authors to get the errata posted as soon as possible in order to save the reputation of the book. I noticed in the acknowledgements that nobody was thanked for checking the book for accuracy . . . I don't think anyone did! With five authors, you'd think one of them could have run all the examples through the latest release of Microsoft software and created an accurate errata. (it's not too late)

Pete911 August 26th, 2010 07:45 PM

Thanks, this fixed the Edit action for me
 
Quote:

Originally Posted by hjbaard (Post 260520)
That is not the only thing you have te change.
To make it work you also have to change the POST Edit method in the controller to let the controller save the changes.

The TryUpdateModel(dinner) will not work anymore because the form values it get are Dinner.Tittle in stead of Tittle.
To fix this you have to add a prefix to the TryUpdateModel (overloaded)

Like this:

[HttpPost]
public ActionResult Edit(int id, FormCollection formValues)
{

Dinner dinner = dinnerRepository.GetDinner(id);
if (TryUpdateModel(dinner, "Dinner"))
{
......
}

Thanks, this fixed the Edit action for me. The code samples in the book have clearly not been checked against ASP.Net MVC2 RTM.

Pretty disappointing, given how much of a fan I am of the authors. Wrox need to post the errata asap.

Denis10101 September 3rd, 2010 04:01 AM

Wrong binding in Create action
 
There is the problem with binding fields in Post Create action. code snippet 1.55.
Some of fields have good binding some of them have null. Do someone have such problem?

Denis10101 September 6th, 2010 03:42 AM

fixed
 
Sorry, guys.
This error was in my code.

atthecom September 14th, 2010 06:49 PM

Great Post
 
Great Post to resolve some of the initial issues in this book. Would be good if WROX could pull together and make sure the Errata is up to date so that the examples in the book flow(although you do learn a lot from having to figure out these sorts of issues on your own).


All times are GMT -4. The time now is 05:11 PM.

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