You said that validation rules can be added in the Model classes and they will be activated whenever the Model is updated or created wherever necessary. But Can i configure the model class to enforce validation rules only certain times and not all the times based on some conditions. If so, how can we configure these things.

]]>Comment Posted by javiglchttp://asp.net/mvc/overview/older-versions/getting-started-with-aspnet-mvc4/adding-validation-to-the-modelSun, 30 Dec 2012 20:40:41 GMT00000000-0000-0000-0000000017090Reviewing the code for view Create.cshtml, under the heading level 2 Create, there are two javascript tags that were not created in my test mvc4 website (VS2010 Web Developer Express). Are they required in the view? Would it be possible to have this explained with more detail in relation to what it does?]]>Comment Posted by vramonahttp://asp.net/mvc/overview/older-versions/getting-started-with-aspnet-mvc4/adding-validation-to-the-modelWed, 16 Jan 2013 11:53:45 GMT00000000-0000-0000-0000000018181Thanks Rick for this tutorial

I still have an issue. I'm french so I appreciated the dot vs comma distinction using Globalize fwk.

With [DataType(DataType.Date)] attribute within the ReleaseDate property of Movie model, it works fine with IE, but not at all with Chrome, it looks like I need to use yyyy-mm-dd format, but I want the same format dd/mm/yyy for both Index and Edit pages and for both IE and Chrome browsers.

]]>Comment Posted by skillfulwebhttp://asp.net/mvc/overview/older-versions/getting-started-with-aspnet-mvc4/adding-validation-to-the-modelTue, 29 Jan 2013 11:40:03 GMT00000000-0000-0000-0000000018276@vramona, I too am having problems with the date field in Chrome (en-US locale.) The bug occurs even with Javascript disabled so this isn't coming from jQuery.

This article [updates.html5rocks.com/] by Kent Tamura (a Chrome software engineer) says the value attribute of a date field should be assigned as yyyy-mm-dd regardless of locale. Using VS2012 Express the value is being rendered as mm/dd/yyyy (en-US)

Is there a work-around?

]]>Comment Posted by JoeBenethttp://asp.net/mvc/overview/older-versions/getting-started-with-aspnet-mvc4/adding-validation-to-the-modelWed, 06 Feb 2013 04:33:58 GMT00000000-0000-0000-0000000018353Took me some time to realize that you have missed adjusting the validation for price range manually:

[Range(1, 100, ErrorMessage="Price must be between $1 and $100")]

Instead i've been trying to find out why I don't get the price range error along with the $ currency in the digits end.

You might want to fix that in the tutorial, And thank you very much for the whole project.

simply amazing! I really am so excited about these new cocepts, they are totally new to me, the DRY, and having validations taken care of by simply working it out in one place such as the Class Movie (the Model).

When I reached the part where you were explaing the string validation for the date and currency, I immediatly started thinking of regular expressions, now I see that we can as well benifit from the regular expressions (those have been very important to me validating prerior to form postback), of course that is in the case the scripts not disabled in the browser! (Thanks for the snapshots Rick, good to know that I could disable those scripts. :-)

Hi Jeff, I had similar error too, but then I realized that I forgot to specify values for the "Rating" in the Seed method in my Configuration.cs, and since I added the "[Required]" attribute for my "rating" field in my Movie Class, then this gets reflected in my Data Table having the column "Rating" Not Null (so it has to have a value).

so what I did, is closed the connection (from Database Explorer), then Deleted the localDB, then went back to the Solution Explorer and Deleted the mdf file from the App_Data, rebuild everything, (of course prior to all that, I updated my Configuration.cs so that my "Rating" field has a value), after all that, I executed the "update-database" from the library package console! Plus all that, I applied the updates in both the Create, and Edit Views so to include the "Rating" label and editor fields.

right, I hope I haven't missed anything. But that what i did, Jeff, Give it a try.

Yes, I just tried what you were pinpointing and very true, I didn't know that, waw! so Chrome renders the page differently than Internet Explorer 9 does. Very interesting to know. Thanks Joe!

so this is another issue I need to look at when developing an application with client side scripting involved, got to make sure it works in chrom too!

thanks joe and everyone!

~Salman~

]]>Comment Posted by ilevin350http://asp.net/mvc/overview/older-versions/getting-started-with-aspnet-mvc4/adding-validation-to-the-modelThu, 21 Feb 2013 19:29:18 GMT00000000-0000-0000-0000000018493I ran into an issue when I tried to add a date range validation to the Movie class:

[Range(typeof(DateTime), "1/1/2010", "1/1/2020")]

public DateTime ReleaseDate{ get; set; }

It turns out that the client side validation using jQuery always fails with a message saying the date must be between "1/1/2010" and "1/1/2020", no matter what I type into the date field, while the server side validation always works (passes if I pass in a valid date string, otherwise fails). Do you see this behavior?

]]>Comment Posted by Acecxhttp://asp.net/mvc/overview/older-versions/getting-started-with-aspnet-mvc4/adding-validation-to-the-modelSat, 02 Mar 2013 08:35:48 GMT00000000-0000-0000-0000000018560The [DataType(DataType.Date)] of verification in lastest Version,when you edit content(Edit.cshtml),The already date data will not be displayed to the date picker.

How to solve it?Thanks!

]]>Comment Posted by aloshinhttp://asp.net/mvc/overview/older-versions/getting-started-with-aspnet-mvc4/adding-validation-to-the-modelMon, 04 Mar 2013 17:06:09 GMT00000000-0000-0000-0000000018572Thanks a lot Rick for this toturial. I tried it and everything worked fine; the only problem I see is the validation message for the "Price" when I am creating or editing a movie record, the validation message shows exactly as "Price must be between 1 to 100" - it doesn't have any "$" in the message. Is there anything that I am missing?

Is there anybody having the same problem?

Thank you all.

]]>Comment Posted by Danny117http://asp.net/mvc/overview/older-versions/getting-started-with-aspnet-mvc4/adding-validation-to-the-modelThu, 07 Mar 2013 16:09:00 GMT00000000-0000-0000-0000000018607I've made it this far. Turned off javascript and still had a working page. Once again I wanted to see cluture done with a bundle. I have to remember. Next time I do a code first migration I want to have the verbose flag on so I can see what's going on.]]>Comment Posted by payinihttp://asp.net/mvc/overview/older-versions/getting-started-with-aspnet-mvc4/adding-validation-to-the-modelMon, 11 Mar 2013 16:52:55 GMT00000000-0000-0000-0000000018651Great tutorials. Thank you.]]>Comment Posted by _Mangohttp://asp.net/mvc/overview/older-versions/getting-started-with-aspnet-mvc4/adding-validation-to-the-modelWed, 08 May 2013 16:53:01 GMT00000000-0000-0000-0000000019073EDIT SPELLING* on Adding Validation to the Model

You have =>"We will us migrations to update the scheam."

Should be => "We will use migrations to update the schema."

Great tutorial btw.

]]>Comment Posted by Aleandaterzinohttp://asp.net/mvc/overview/older-versions/getting-started-with-aspnet-mvc4/adding-validation-to-the-modelFri, 21 Jun 2013 08:11:02 GMT00000000-0000-0000-0000000019361I don't understand where I have to put the globalize.js, cultures/globalize.cultures.js and the @section Scripts.]]>Comment Posted by kileys.http://asp.net/mvc/overview/older-versions/getting-started-with-aspnet-mvc4/adding-validation-to-the-modelThu, 11 Jul 2013 16:50:38 GMT00000000-0000-0000-0000000019548I've made it this far, no errors and learning a tonne! Thank you for all of this work. The tutorials and screenshots are spot on.

I would ultimately like to build an MVC app with logging in/out privileges. For example, continue the movie example but have an account which can do the CRUD mechanics. Any tips?

Small Grammar N@z! point, "the form is not posted to the server when their are validation errors detected on the client side; the second Create method is never called." their -> there.

]]>Comment Posted by jteppinettehttp://asp.net/mvc/overview/older-versions/getting-started-with-aspnet-mvc4/adding-validation-to-the-modelMon, 15 Jul 2013 02:50:29 GMT00000000-0000-0000-0000000019574For everyone who was having issues with the validation error, "Price must be between $1 and $100"

]]>Comment Posted by bhjerryhttp://asp.net/mvc/overview/older-versions/getting-started-with-aspnet-mvc4/adding-validation-to-the-modelMon, 25 Nov 2013 16:54:01 GMT00000000-0000-0000-0000000022061Rick, is there any way to definition the Validation Error info in some non-English language?

For example that my application is for Spanish speaking people, how can I change "The Title field is required" to Spanish? Or in my own words?