<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Adding Validation to the Model</title><link>http://www.asp.net</link><pubDate>Fri, 15 Mar 2013 14:26:27 GMT</pubDate><generator>umbraco</generator><description>Comments for Adding Validation to the Model</description><language>en</language><atom:link href="http://www.asp.net/rss/comments/27656" rel="self" type="application/rss+xml" /><item><title>Comment Posted by Rainer Hilmer</title><link>http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/adding-validation-to-the-model</link><pubDate>Wed, 02 Feb 2011 04:18:44 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000011898</guid><description><![CDATA[ <p>This is great! Thanks a lot ricka6. :-)</p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/Rainer%20Hilmer.jpg?forceidenticon=false&amp;dt=635050863600000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by cogito</title><link>http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/adding-validation-to-the-model</link><pubDate>Sat, 05 Feb 2011 18:00:50 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000011942</guid><description><![CDATA[ <p>This tutorial is truly great, thanks a lot.</p><p>There is only one problem I have with this: Model validation shows error message on [Range(1, 100, ErrorMessage = &quot;Price must be between $1 and $100&quot;)] methods_de was fixing the decimal comma issue before, but now that range check have problem with it. Cheers.</p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/cogito.jpg?forceidenticon=false&amp;dt=635050863600000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by cylon cat</title><link>http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/adding-validation-to-the-model</link><pubDate>Sun, 06 Feb 2011 13:20:52 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000011948</guid><description><![CDATA[ <p>Great tutorial, but I have to say that EFCodeFirst is not ready for prime time. I routinely work with very large databases that contain a lot of provisioning data; dropping and recreating the database on a model change is simply not feasible. But EFCodeFirst is very sensitive about how you change the database schema, and the error message is quite useless, in that it gives no clue about what it choked on, much less how to fix it. I can bypass the error by going to the Create page first, then back to the list, and the list displays. But if I start with the list page, EFCodeFirst dies.</p><p></p><p>However, the big problem with &quot;drop and recreate&quot; is that eventually, applications go into production. It&#39;s far too easy to forget that this &quot;developer short-cut&quot; is in the code, and needs to be removed. It&#39;s much better to teach people the right way first, even if it adds a page to the tutorial.</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/cylon%20cat.jpg?forceidenticon=false&amp;dt=635050863600000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by vrodax</title><link>http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/adding-validation-to-the-model</link><pubDate>Thu, 05 May 2011 23:21:11 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000013084</guid><description><![CDATA[ <p>I believe that there is an error above. I believe that the intended code was:</p><p></p><p>[DisplayFormat(DataType.Date)]</p><p></p><p>instead of:</p><p></p><p>[DataType(DataType.Date)] </p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/vrodax.jpg?forceidenticon=false&amp;dt=635050863600000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by ricka6</title><link>http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/adding-validation-to-the-model</link><pubDate>Wed, 11 May 2011 23:15:55 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000013137</guid><description><![CDATA[ <p>vrodax : [DisplayFormat(DataType.Date)] is not correct while [DataType(DataType.Date)] works.</p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/ricka6.jpg?forceidenticon=false&amp;dt=635050863600000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by DilutedImage</title><link>http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/adding-validation-to-the-model</link><pubDate>Tue, 31 May 2011 23:17:53 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000013349</guid><description><![CDATA[ <p>Great write-up; thanks!</p><p></p><p>I&#39;m having an issue with fields I do NOT want to be required. I excluded the Required attribute from ReleaseDate, but a validation error is still thrown. Any insight would be greatly appreciated.</p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/DilutedImage.jpg?forceidenticon=false&amp;dt=635050863600000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by PointZeroTwo</title><link>http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/adding-validation-to-the-model</link><pubDate>Thu, 16 Jun 2011 11:18:23 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000013540</guid><description><![CDATA[ <p>DilutedImage: Value types (like DateTime and numeric types) cannot be null in C#, so a value is required.</p><p></p><p>To make the ReleaseDate optional, make it nullable by adding a question mark after the type (public DateTime? ReleaseDate...).  This causes &quot;Allow Null&quot; to be True in the generated DB column.  </p><p></p><p></p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/PointZeroTwo.jpg?forceidenticon=false&amp;dt=635050863600000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by basbak</title><link>http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/adding-validation-to-the-model</link><pubDate>Sun, 07 Aug 2011 19:07:26 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000013919</guid><description><![CDATA[ <p>[DataType(DataType.Currency)]</p><p>        [DisplayFormat(DataFormatString = &quot;{0:c}&quot;, HtmlEncode=false)]</p><p>        [Required(ErrorMessage = &quot;Price missing&quot;)]</p><p>        [Range(1, 100, ErrorMessage = &quot;Price must be between 1 and 100&quot;)] </p><p>        public decimal Price { get; set; }</p><p></p><p>The proceeding code does not allow input of commas which is used as decimal point for foreign currencies.</p><p></p><p>if I enter 9,99 it gives --&gt; the price must be a number.</p><p>then if I enter 9.99 it gives --&gt; 9.99 is not valid for price.</p><p></p><p>So, any way to solve this problem in Edit and in Create ?</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/basbak.jpg?forceidenticon=false&amp;dt=635050863600000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by ricka6</title><link>http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/adding-validation-to-the-model</link><pubDate>Sat, 13 Aug 2011 02:23:51 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000013955</guid><description><![CDATA[ <p>basbak : see <a rel="nofollow" href="http://msdn.microsoft.com/en-us/library/gg674880(VS.98).aspx" target="_blank">msdn.microsoft.com/</a></p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/ricka6.jpg?forceidenticon=false&amp;dt=635050863600000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by everen</title><link>http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/adding-validation-to-the-model</link><pubDate>Wed, 24 Aug 2011 09:23:24 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000014036</guid><description><![CDATA[ <p>I have the same problem as basbak in the above posting with RANGE.</p><p></p><p>Without Range it works fine using the method_de.js file with this and this in the Views/Movies/Create.cshtml file:</p><p></p><p></p><p>4. Add a reference to the script after the two other script references in the Views/Movies/Create.cshtml file:</p><p></p><p>&lt;script src=&quot;@Url.Content(&quot;~/Scripts/jquery.validate.min.js&quot;)&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</p><p>&lt;script src=&quot;@Url.Content(&quot;~/Scripts/jquery.validate.unobtrusive.min.js&quot;)&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</p><p>&lt;script src=&quot;@Url.Content(&quot;~/Scripts/methods_de.js&quot;)&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; </p><p></p><p>The above link to MSDN doesn&#39;t lead to anything helpful regarding the Range attribute. What I and other non-english user wnat to know is &quot;What to type and where to type it&quot;. Until that is resolved I&#39; put 2010 express on the shelf. It give me the impression of not being an Internationally mature product yet.</p><p></p><p>Anyway, thanx for all the work with this guide.</p><p></p><p></p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/everen.jpg?forceidenticon=false&amp;dt=635050863600000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by matt.g</title><link>http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/adding-validation-to-the-model</link><pubDate>Tue, 30 Aug 2011 20:11:51 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000014091</guid><description><![CDATA[ <p>Since MVC is so much about best-practice development and code, </p><p>wouldn&#39;t it make more sense if the javascript files in the _Layout.cshtml were placed at the end of the page prior to the </p><p>closing &lt;/body&gt; tag instead of in the header? </p><p></p><p>I suppose that makes including extra scripts such as jquery </p><p>dependent plug-ins more/too complex than it ought to be...</p><p></p><p><a rel="nofollow" href="http://developer.yahoo.com/performance/rules.html#js_bottom" target="_blank">developer.yahoo.com/</a></p><p></p><p>Thanks. </p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/matt.g.jpg?forceidenticon=false&amp;dt=635050863600000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by matt.g</title><link>http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/adding-validation-to-the-model</link><pubDate>Wed, 31 Aug 2011 18:21:03 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000014097</guid><description><![CDATA[ <p>Looks as though Razor could make this easy.</p><p><a rel="nofollow" href="http://weblogs.asp.net/scottgu/archive/2010/12/30/asp-net-mvc-3-layouts-and-sections-with-razor.aspx" target="_blank">weblogs.asp.net/</a> </p><p></p><p>The bottom of the _Layout.cshtml could read as: </p><p></p><p>&lt;script src=&quot;@Url.Content(&quot;~/Scripts/jquery-1.6.2.min.js&quot;)&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</p><p>&lt;script src=&quot;@Url.Content(&quot;~/Scripts/modernizr-2.0.6-development-only.js&quot;)&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</p><p>@RenderSection(&quot;extra_js&quot;, required: false)</p><p>&lt;/body&gt;</p><p>&lt;/html&gt;</p><p></p><p>Then in the /Movies/Edit.cshtml page: </p><p></p><p>@section extra_js {</p><p>&lt;script src=&quot;@Url.Content(&quot;~/Scripts/jquery.validate.min.js&quot;)&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</p><p>&lt;script src=&quot;@Url.Content(&quot;~/Scripts/jquery.validate.unobtrusive.min.js&quot;)&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</p><p>}</p><p></p><p>The tutorial could likely include this without adding much complexity,</p><p>and it might be a nice intro to how layouts can work in Razor. Have to say, looks much better than the webforms master page mode of design.</p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/matt.g.jpg?forceidenticon=false&amp;dt=635050863600000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by Oleh.Zheleznyak</title><link>http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/adding-validation-to-the-model</link><pubDate>Mon, 16 Apr 2012 16:19:40 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000015349</guid><description><![CDATA[ <p>Thanks for the great article.</p><p>I feel obliged to point out, however, that DRY, is not only a design tenet of MVC, but one of the fundamental paradigms in OOP/OOD. It&#39;s very hard to overestimate the importance of this principle. Meta-programming really helps keeping things DRY, and has been around, (in the form of attributes) since .NET 1.1, so this is also not MVC - specific. </p><p>What really interests me most, as a freshman to web, is how to keep the views DRY? They clearly contain repetitive code</p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/Oleh.Zheleznyak.jpg?forceidenticon=false&amp;dt=635050863600000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by justin_cie2</title><link>http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/adding-validation-to-the-model</link><pubDate>Mon, 23 Apr 2012 00:49:03 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000015393</guid><description><![CDATA[ <p>I totally agree with cylon cat.</p><p>I noticed after I modified my Movie.cs, run app, and browse the movies controller;</p><p>the &#39;Rio Bravo II&#39; record is missing...</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/justin_cie2.jpg?forceidenticon=false&amp;dt=635050863600000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by bassam.mo7amed</title><link>http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/adding-validation-to-the-model</link><pubDate>Mon, 30 Apr 2012 05:32:21 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000015432</guid><description><![CDATA[ <p>First I would like to thank you for this great article but I have a question </p><p>What about if I regenerate the model classes again then I will lost all the validation </p><p>So there no idea to separate the model awy from the validation or some thing likes that ?</p><p></p><p></p><p>thanks </p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/bassam.mo7amed.jpg?forceidenticon=false&amp;dt=635050863600000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by superandi</title><link>http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/adding-validation-to-the-model</link><pubDate>Wed, 06 Jun 2012 15:41:52 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000015700</guid><description><![CDATA[ <p>For all non-English ppl, at least the ones with the ./, problem and decimal places (Price must be between $1 and $100), have a look here at my great site :) <a rel="nofollow" href="http://www.andreas-reiff.de/2012/06/probleme-mit-mvcmovies-beispiel-validierung-des-preises-mit-dezimalstellen-schlagt-fehl/" target="_blank">www.andreas</a>#more-1939 (German) or at Stackoverflow, where I got the idea from. Good (?) to see that there were no answers here before....................</p><p><a rel="nofollow" href="http://stackoverflow.com/questions/5199835/mvc-3-jquery-validation-globalizing-of-number-decimal-field" target="_blank">stackoverflow.com/</a></p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/superandi.jpg?forceidenticon=false&amp;dt=635050863600000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by cjduva</title><link>http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/adding-validation-to-the-model</link><pubDate>Sun, 29 Jul 2012 11:06:14 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000016063</guid><description><![CDATA[ <p>Thank you very much!  This really lays out the building blocks for MVC and Razor for someone coming from a web forms background.  I will be moving on to next tutorial.  I will be re-writing my commercial web app using MVC and Razor (I am also making the jump from VB to C#).  The code line count will probably drop 90%.</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/cjduva.jpg?forceidenticon=false&amp;dt=635050863600000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by rgamage</title><link>http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/adding-validation-to-the-model</link><pubDate>Mon, 15 Oct 2012 13:55:48 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000016628</guid><description><![CDATA[ <p>Is it just me or does it seem odd to specify display formatting in the Model?  Doesn&#39;t that stuff belong in the View?</p><p></p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/rgamage.jpg?forceidenticon=false&amp;dt=635050863600000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by vectorman</title><link>http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/adding-validation-to-the-model</link><pubDate>Thu, 08 Nov 2012 16:18:17 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000016769</guid><description><![CDATA[ <p>Why again MS going codebehind for validation, for client side work? I think this is not good for mvc, Everybody can validate with js, JQ etc. ok i accept this is easy but, ms dont need that kind of validation. Developers wants to free on client side. I want to ask : which code is validating? how can i change validation script codes? Is there any webresource.axd again? or MVC is making it JQuery? Have to i use JQ in all apps if via JQuery? What will happen i don&#39;t want to use JQ.</p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/vectorman.jpg?forceidenticon=false&amp;dt=635050863600000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by shamimbd0</title><link>http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/adding-validation-to-the-model</link><pubDate>Sun, 03 Feb 2013 05:16:16 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000018330</guid><description><![CDATA[ <p>Excellent  validation! </p><p>It&#39;s easy. </p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/shamimbd0.jpg?forceidenticon=false&amp;dt=635050863600000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by jkenny6</title><link>http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/adding-validation-to-the-model</link><pubDate>Fri, 08 Feb 2013 04:29:18 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000018382</guid><description><![CDATA[ <p>How do you add and use a razor  editor template.  Cant find anything on it.  there is a solution to a problem I am having but do not know how to implement it.</p><p></p><p><a rel="nofollow" href="http://stackoverflow.com/questions/8516940/client-side-validation-of-input-type-date-does-not-work" target="_blank">stackoverflow.com/</a></p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/jkenny6.jpg?forceidenticon=false&amp;dt=635050863600000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by ramonmico</title><link>http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/adding-validation-to-the-model</link><pubDate>Fri, 15 Mar 2013 14:26:27 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000018709</guid><description><![CDATA[ <p>Validation for price must be link below;</p><p></p><p>[Required(ErrorMessage = &quot;Price Required&quot;)]</p><p>[RegularExpression(@&quot;[+]?\d+\,?\d*&quot;,ErrorMessage=&quot;Bad number string&quot;)]</p><p>[Range(1.0, 100.0, ErrorMessage = &quot;Price must be between $1 and $100&quot;)]</p><p>[DisplayFormat(DataFormatString = &quot;{0:c}&quot;)]</p><p>public decimal Price { get; set; }</p><p></p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/ramonmico.jpg?forceidenticon=false&amp;dt=635050863600000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item></channel></rss>