Wrox Programmer Forums

Need to download code?

View our list of code downloads.

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
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 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
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
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.
Reply With Quote
  #2 (permalink)  
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.
Reply With Quote
  #3 (permalink)  
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
Reply With Quote
  #4 (permalink)  
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.
Reply With Quote
  #5 (permalink)  
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.
Reply With Quote
  #6 (permalink)  
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.
Reply With Quote
  #7 (permalink)  
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.
Reply With Quote
  #8 (permalink)  
Old October 21st, 2009, 08:01 PM
Registered User
 
Join Date: Oct 2009
Location: Mequon, WI
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
Reply With Quote
  #9 (permalink)  
Old October 21st, 2009, 08:07 PM
Registered User
 
Join Date: Oct 2009
Location: Mequon, WI
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Looks like this issue has already been noted here:

Chapter 1 - NerdDinner - Errors
Reply With Quote
Reply


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
Unable to view page from IE angshujit ASP.NET 2.0 Basics 0 January 10th, 2007 02: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 02:08 PM



All times are GMT -4. The time now is 09:50 AM.


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