|
|
 |
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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

May 9th, 2009, 12:02 AM
|
|
Registered User
|
|
Join Date: May 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|

June 10th, 2009, 07:36 AM
|
|
Authorized User
|
|
Join Date: Jun 2009
Posts: 19
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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 AddMod elErrors and not AddMod alErrors?
Hope this helps!
S.
|

June 10th, 2009, 08:38 PM
|
|
Registered User
|
|
Join Date: May 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you for the Countries correction.
The second issue is still a problem as I had posted AddMod alErrors but I actually did have the code, AddMod elErrors. 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
|

June 11th, 2009, 04:52 AM
|
|
Authorized User
|
|
Join Date: Jun 2009
Posts: 19
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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.
|

June 12th, 2009, 02:25 PM
|
|
Authorized User
|
|
Join Date: Jun 2009
Posts: 19
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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.
|

June 13th, 2009, 10:28 AM
|
|
Registered User
|
|
Join Date: May 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|

June 13th, 2009, 12:57 PM
|
|
Authorized User
|
|
Join Date: Jun 2009
Posts: 19
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Good Luck!
Good luck for your interview.
S.
|

October 21st, 2009, 09:01 PM
|
|
Registered User
|
|
Join Date: Oct 2009
Location: Mequon, WI
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

October 21st, 2009, 09:07 PM
|
|
Registered User
|
|
Join Date: Oct 2009
Location: Mequon, WI
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Looks like this issue has already been noted here:
Chapter 1 - NerdDinner - Errors
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |