Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > BOOK: Professional ASP.NET MVC 1.0 ISBN: 978-0-470-38461-9
|
BOOK: Professional ASP.NET MVC 1.0 ISBN: 978-0-470-38461-9
This is the forum to discuss the Wrox book Professional ASP.NET MVC 1.0 by Rob Conery, Scott Hanselman, Phil Haack, Scott Guthrie; ISBN: 978-0-470-38461-9
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET MVC 1.0 ISBN: 978-0-470-38461-9 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 May 8th, 2009, 11:02 PM
Registered User
 
Join Date: May 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default AddModalErrors and AllCountries page 87 View Data Dictionary

When I try to use ModalState.AddModalErrors I get an error <'System.Web.Mvc.ModalStateDictionary' does not contain a definition for 'AddModalErrors'>.

Similarly, when I try to use AllCountries I get this error <'NerdDinner.Controllers.PhoneValidator' does not contain a definition for 'AllCountries'>

I cannot seem to track down where I all of the sudden went wrong. Can anyone point me in the right direction?

Thx for looking and any help.
 
Old June 10th, 2009, 06:36 AM
Authorized User
 
Join Date: Jun 2009
Posts: 20
Thanks: 0
Thanked 1 Time in 1 Post
Default Errata

Hi barnettrob,
...AllCountries... should be just ...Countries... (Please take a look at the errata page)

As for the next problem, shouldn't it be AddModelErrors and not AddModalErrors?

Hope this helps!

S.
 
Old June 10th, 2009, 07:38 PM
Registered User
 
Join Date: May 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for the Countries correction.

The second issue is still a problem as I had posted AddModalErrors but I actually did have the code, AddModelErrors. I had copied it from:

http://nerddinnerbook.s3.amazonaws.com/Part6.htm

it still errors:

'System.Web.Mvc.ModelStateDictionary' does not contain a definition for 'AddModelErrors' and no extension method 'AddModelErrors' accepting a first argument of type 'System.Web.Mvc.ModelStateDictionary' could be found (are you missing a using directive or an assembly reference?)

I checked the Errata but it does not offer a solution to that one.

Thanks for the other answer
 
Old June 11th, 2009, 03:52 AM
Authorized User
 
Join Date: Jun 2009
Posts: 20
Thanks: 0
Thanked 1 Time in 1 Post
Default Missing using statement?

Hi barnettrob,
Are you missing using statement at the top of your class file? If you recall that you added an extension method in order to be able to add rule-violations to the ModelState dictionary directly. You need to add add reference to the namespace which contains the extension method definition from pages 70-71.

See if that works.

Good luck!

S.
 
Old June 12th, 2009, 01:25 PM
Authorized User
 
Join Date: Jun 2009
Posts: 20
Thanks: 0
Thanked 1 Time in 1 Post
Default Problem solved?

Hi barnettrob,
Did you manage to solve your problem? It would be helpful for other readers to know how you resolved your issue.

Thanks,
S.
 
Old June 13th, 2009, 09:28 AM
Registered User
 
Join Date: May 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry about that. No I have not solved the problem. I reverted all my code back to way it was at the end of Step 5. Everything was working as it should then (except for the page title on aspx pages, but no big deal there).

I was getting ready to start Step 6 again but I have not yet had a chance. Sometime soon - but I am prepping for a technical interview Tuesday. Even though it's a UI Developer position, they want someone who understands middle tier service code.
 
Old June 13th, 2009, 11:57 AM
Authorized User
 
Join Date: Jun 2009
Posts: 20
Thanks: 0
Thanked 1 Time in 1 Post
Default Good Luck!

Good luck for your interview.

S.
 
Old October 21st, 2009, 08:01 PM
Registered User
 
Join Date: Oct 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default AddRuleViolations vs. AddModelErrors

Regarding your error: "'System.Web.Mvc.ModelStateDictionary' does not contain a definition for 'AddModelErrors' and no extension method 'AddModelErrors' accepting a first argument of type 'System.Web.Mvc.ModelStateDictionary' could be found (are you missing a using directive or an assembly reference?)"

I received the same error and noticed some inconsistencies in the text, unless I'm missing something?

In Part 5, they have you create this function:

Code:
public static class ControllerHelpers {
 
public static void AddRuleViolations(this ModelStateDictionary modelState, IEnumerable<RuleViolation> errors) {
 
foreach (RuleViolation issue in errors) {
modelState.AddModelError(issue.PropertyName, issue.ErrorMessage);
}
}
}
For the rest of the instructions on Part 5 , they consistently have you call 'AddRuleViolations'.

In Part 6, the same functions that were calling 'AddRuleViolations' are now calling 'AddModelErrors', such as:

Code:
//
// POST: /Dinners/Edit/5
 
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(int id, FormCollection collection) {
 
Dinner dinner = dinnerRepository.GetDinner(id);
 
try {
UpdateModel(dinner);
 
dinnerRepository.Save();
 
return RedirectToAction("Details", new { id=dinner.DinnerID });
}
catch {
ModelState.AddModelErrors(dinner.GetRuleViolations());
 
return View(new DinnerFormViewModel(dinner));
}
}
I changed the name of the function 'AddRuleViolations' to 'AddModelErrors', which resolved my problem.

Did I miss something in the text, or is this an outdated version?

Regards,
Karsten
 
Old October 21st, 2009, 08:07 PM
Registered User
 
Join Date: Oct 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Looks like this issue has already been noted here:

Chapter 1 - NerdDinner - Errors





Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to view page from IE angshujit ASP.NET 2.0 Basics 0 January 10th, 2007 03:17 AM
Direct Child Selector Question - P86-87 MRoberts BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 1 May 22nd, 2005 04:48 PM
Data Dictionary shamsad Oracle 1 February 25th, 2004 03:08 PM





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