Album Class


I agree with others who appreciate the work of creating this tutorial for us since there is a dearth of book available. I have had some difficulties because I've never used MVC so it's taking a while to understand everything. I'm now at page 62 and started getting errors after adding the Album class.

At the end of page 62 it says the Create and Debit screens begin validating fields but I get errors when I try them.

For StoreManager/Create I'm Getting this error - "This property cannot be set to a null value"
For this line - _Title = StructuralObject.SetValidValue(value, false);

And no red error messages.

And it's crashing for StoreManager/Edit

Did I miss something or do something wrong? One of my friends is having a similar problem.



Andronicus wrote Jul 15, 2010 at 3:39 PM

Jon, I also appreciate your work in putting this tutorial together. I am experiencing the same issue as JMPlex.

jongalloway wrote Jul 24, 2010 at 6:31 AM

You will see an exception when you only have server-side validation hooked up. That's expected. If you hit F5 to continue executing, you'll see the page display. The next part of the tutorial hooks up Client-Side Validation, and you'll stop seeing exceptions since the validation errors will be handled on the client. Make sense?

slink9 wrote Jul 30, 2010 at 1:35 PM

I was having the same problem and I continued on through the next couple of pages to set up client side validation. I have tried the javascript references in both the master page and in the album editor template and have added enableclientvalidation into both create and edit.aspx but it still blows at the same place, but displays properly after F5 is used. Is there some kind of previous setting that I could have missed? Is there a setting in IE8 that could be preventing this from working properly?

Andronicus wrote Jul 31, 2010 at 1:16 PM

Thanks Jon, as you said, after setting up the Client-Side Validation, all is well.

rspaulino wrote Aug 18, 2010 at 3:21 AM

@jongallaway, first at all i want to say thank you for this great tutorial, this is a great way to learn this new technology.

i bing everywhere trying to find a deeper detail answer on why i get this exception, i know that by pressing F5 it will make the server-validation work or by running the the solution with ctrl+f5, i even had a break point on the HTTPOST create and it get hit after it go through the edmx so it make it feel like a late binding is this something normal? I thought that by using partial classes the compiler with merge this two into one at runtime. I know that the client validation won't make it work and even do this is just a sample I don't want to relay on client validation and yes even do the server-validation will work i just wondering why ain't kicking on debug mode?

jongalloway wrote Aug 31, 2010 at 6:22 PM

The reasons are confusing, but that exception is expected. Nothing's wrong with your code, and everything is working as it should.

Entity Framework throws exceptions when checking constraints, and MVC handles them. When you run without debugging, or just hit F5 when the exception occurs, you'll see that the page is rendered. Visual Studio breaks on the exception because the Entity Framework code is a generated C# class in your project, so it's technically "your code", and the default behavior for Visual Studio is to break on unhandled errors in user code.

Tony_P wrote Sep 24, 2010 at 7:15 AM

for me i just change "false" to "true" and the validation works