<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>Wed, 10 Nov 2010 14:35:51 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/33032" rel="self" type="application/rss+xml" /><item><title>Comment Posted by ned_a._job</title><link>http://www.asp.net/mvc/tutorials/older-versions/getting-started-with-mvc/getting-started-with-mvc-part7</link><pubDate>Fri, 20 Aug 2010 21:22:50 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000009931</guid><description><![CDATA[ <p>Before adding javascripts to the Create.aspx file where it says &quot;Adding Client-Side Validation&quot;</p><p>i kept getting the below error message that would freeze the program:</p><p></p><p>System.Data.ConstraintException was unhandled by user code</p><p>  Message=This property cannot be set to a null value.</p><p>  Source=System.Data.Entity</p><p>  StackTrace:</p><p>       at System.Data.Objects.DataClasses.StructuralObject.SetValidValue(String value, Boolean isNullable)</p><p>       at Movies.Models.Movie.set_Title(String value) in C:\Users\Ned\documents\visual studio 2010\Projects\Movies\Movies\Models\Movies.Designer.cs:line 177</p><p>  InnerException: </p><p></p><p></p><p>After i had the javascripts, I found that not only the Title and Price fields were validate but the Release Date field was</p><p>validated as well. I don&#39;t know why the Genre field was not validated. shouldn&#39;t they all be validated</p><p>by the mvcvalidation javascript?</p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/ned_a._job.jpg?forceidenticon=false&amp;dt=635051580000000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by mdrake411</title><link>http://www.asp.net/mvc/tutorials/older-versions/getting-started-with-mvc/getting-started-with-mvc-part7</link><pubDate>Mon, 23 Aug 2010 17:24:02 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000009950</guid><description><![CDATA[ <p>I am not getting the validation to work as written in this article. For example, submitting an empty Title, I get the error message &quot;The value &#39;&#39; is invalid.&quot; And, Price only valdates the existence of a value, but not the specified range. This tells me there is some default behavior kicking in, while the custom partial class (shown above) is being ignored.</p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/mdrake411.jpg?forceidenticon=false&amp;dt=635051580000000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by chris.hore</title><link>http://www.asp.net/mvc/tutorials/older-versions/getting-started-with-mvc/getting-started-with-mvc-part7</link><pubDate>Wed, 25 Aug 2010 23:25:06 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000009990</guid><description><![CDATA[ <p>As written the validation does not appear to work for Genre but does work for the other fields.</p><p></p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/chris.hore.jpg?forceidenticon=false&amp;dt=635051580000000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by Gary A. Stafford</title><link>http://www.asp.net/mvc/tutorials/older-versions/getting-started-with-mvc/getting-started-with-mvc-part7</link><pubDate>Sat, 11 Sep 2010 17:15:17 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000010191</guid><description><![CDATA[ <p>No Movies.cs was ever created originally (see comments in other tutorial). I created an ADO.NET EntityObject Generator item to keep going. Now the valaidation won&#39;t work in the partial class. Null values are caught by the EntityObject.</p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/Gary%20A.%20Stafford.jpg?forceidenticon=false&amp;dt=635051580000000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by shanselman</title><link>http://www.asp.net/mvc/tutorials/older-versions/getting-started-with-mvc/getting-started-with-mvc-part7</link><pubDate>Sat, 18 Sep 2010 06:11:14 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000010282</guid><description><![CDATA[ <p>Gary, email me at scottha@microsoft.com as you have the keenest eye. Perhaps I&#39;ve been staring at this too long. </p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/shanselman.jpg?forceidenticon=false&amp;dt=635051580000000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by RodWittmier</title><link>http://www.asp.net/mvc/tutorials/older-versions/getting-started-with-mvc/getting-started-with-mvc-part7</link><pubDate>Sat, 18 Sep 2010 22:58:33 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000010291</guid><description><![CDATA[ <p>The instruction for including the scripts &quot;...drag the following three scripts to within the head tag&quot; needs to be rewritten as there is no head tag since the page is using a Master page.  It should say to the top of the 2nd Content tag or just before the h2 tag.</p><p></p><p>It&#39;s very cool that adding the attributes of [Required..] and [Range...] do so much for us automatically.  Great demo of the value of having a Framework! </p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/RodWittmier.jpg?forceidenticon=false&amp;dt=635051580000000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by heraclito27</title><link>http://www.asp.net/mvc/tutorials/older-versions/getting-started-with-mvc/getting-started-with-mvc-part7</link><pubDate>Mon, 20 Sep 2010 12:35:02 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000010313</guid><description><![CDATA[ <p>Same as chris.hore, everything is working except for Genre. I don&#39;t understand why isn&#39;t validated as required.</p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/heraclito27.jpg?forceidenticon=false&amp;dt=635051580000000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by ritchiep</title><link>http://www.asp.net/mvc/tutorials/older-versions/getting-started-with-mvc/getting-started-with-mvc-part7</link><pubDate>Wed, 22 Sep 2010 13:17:45 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000010335</guid><description><![CDATA[ <p>It should be &quot;Right click on the *Models* folder and select Add Class&quot; (asterisk for highlighting) not &quot;Right click on the Model folder and select Add Class&quot; in the 2nd paragraph.</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/ritchiep.jpg?forceidenticon=false&amp;dt=635051580000000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by ritchiep</title><link>http://www.asp.net/mvc/tutorials/older-versions/getting-started-with-mvc/getting-started-with-mvc-part7</link><pubDate>Wed, 22 Sep 2010 13:21:22 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000010336</guid><description><![CDATA[ <p>In Adding Client-Side Validation, it should be Views\Movies (not Views\Movie) to match what is described in previous steps.</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/ritchiep.jpg?forceidenticon=false&amp;dt=635051580000000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by ritchiep</title><link>http://www.asp.net/mvc/tutorials/older-versions/getting-started-with-mvc/getting-started-with-mvc-part7</link><pubDate>Wed, 22 Sep 2010 13:26:46 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000010341</guid><description><![CDATA[ <p>You detail &quot;...scripts to within the &lt;head&gt; tag.&quot;  But, there is no head tag in Create.aspx, and the resulting screen shot shows they should be dragged to the &lt;asp:Content ID=&quot;Content2&quot;&gt; tag.</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/ritchiep.jpg?forceidenticon=false&amp;dt=635051580000000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by ritchiep</title><link>http://www.asp.net/mvc/tutorials/older-versions/getting-started-with-mvc/getting-started-with-mvc-part7</link><pubDate>Wed, 22 Sep 2010 13:29:20 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000010342</guid><description><![CDATA[ <p>I don&#39;t understand Gary A. Stafford&#39;s comment, following the instructions up to now (and compensating with my comments) results in no Movies.cs file being created--only a Movie.cs file...</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/ritchiep.jpg?forceidenticon=false&amp;dt=635051580000000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by aral1108</title><link>http://www.asp.net/mvc/tutorials/older-versions/getting-started-with-mvc/getting-started-with-mvc-part7</link><pubDate>Sun, 26 Sep 2010 05:20:48 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000010388</guid><description><![CDATA[ <p>as ritchiep says, following the instructions everything works fine. Perhaps some problems arise if you are not using VS2010 and MVC2. I don&#39;t understand either that Movies.cs comment, perhaps you are looking for the complement to the partial class just created here you can find it in Movies.Designer.cs</p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/aral1108.jpg?forceidenticon=false&amp;dt=635051580000000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by greengirl</title><link>http://www.asp.net/mvc/tutorials/older-versions/getting-started-with-mvc/getting-started-with-mvc-part7</link><pubDate>Thu, 30 Sep 2010 11:27:36 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000010448</guid><description><![CDATA[ <p>... Hi Scot, Thanks for these lessons, coming this far, it&#39;s almost a miracle, feeling almost as smart as your wife sister parking a car backward figuring out why it does not steer with four wheels instead of two (your presentation DevDays The Hague, April 2010) ... apparently again a little (essential) part is missing ... are these tutorial being re-reviewed?</p><p></p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/greengirl.jpg?forceidenticon=false&amp;dt=635051580000000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by greengirl</title><link>http://www.asp.net/mvc/tutorials/older-versions/getting-started-with-mvc/getting-started-with-mvc-part7</link><pubDate>Thu, 30 Sep 2010 11:35:32 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000010449</guid><description><![CDATA[ <p>... what I meant to state here is: bypassing the other hurdles, coming this far, I can&#39;t get the Client site validation working. As already mentioned by others at this create.aspx there are not &lt;head&gt;&lt;/head&gt;-tags, just putting in the &quot;MainContent&quot; as suggested ??? </p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/greengirl.jpg?forceidenticon=false&amp;dt=635051580000000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by dehnel</title><link>http://www.asp.net/mvc/tutorials/older-versions/getting-started-with-mvc/getting-started-with-mvc-part7</link><pubDate>Tue, 12 Oct 2010 21:24:22 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000010588</guid><description><![CDATA[ <p>Interesting - when I attempted a validation test only missing the title I got the following debug error:</p><p></p><p>System.Data.ConstraintException was unhandled by user code</p><p>  Message=This property cannot be set to a null value.</p><p>  Source=System.Data.Entity</p><p>  StackTrace:</p><p>       at System.Data.Objects.DataClasses.StructuralObject.SetValidValue(String value, Boolean isNullable)</p><p>       at MoviesII.Models.Movie.set_Title(String value) in ...\Models\Movies.Designer.cs:line 179</p><p>  InnerException:</p><p></p><p>But when I closed the popup and reran the project the Html page was correct with the &quot;blank&quot; title and the red &quot;Titles are required&quot;</p><p></p><p>Great Lessons by the way - and free to - Thanks for everything!</p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/dehnel.jpg?forceidenticon=false&amp;dt=635051580000000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by merin</title><link>http://www.asp.net/mvc/tutorials/older-versions/getting-started-with-mvc/getting-started-with-mvc-part7</link><pubDate>Fri, 22 Oct 2010 02:53:25 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000010708</guid><description><![CDATA[ <p>To chris.hore and heraclito27,</p><p>Genre is not validated because we did not have code for Genre validation. If you want to validate Genre also, then you need to add this code inside the Movie class</p><p></p><p>   [Required(ErrorMessage = &quot;Enter the Genre.&quot;)]</p><p>   public string Name { get; set; }</p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/merin.jpg?forceidenticon=false&amp;dt=635051580000000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by FMastro</title><link>http://www.asp.net/mvc/tutorials/older-versions/getting-started-with-mvc/getting-started-with-mvc-part7</link><pubDate>Fri, 22 Oct 2010 10:05:08 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000010713</guid><description><![CDATA[ <p>I can&#39;t get this Partial Movie class validation working at all.</p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/FMastro.jpg?forceidenticon=false&amp;dt=635051580000000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by FMastro</title><link>http://www.asp.net/mvc/tutorials/older-versions/getting-started-with-mvc/getting-started-with-mvc-part7</link><pubDate>Fri, 22 Oct 2010 10:14:38 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000010714</guid><description><![CDATA[ <p>hey got it working. for vb.net you have to remove the namespace since VB it&#39;s already built in and you don&#39;t need to add it twice.</p><p></p><p>VB.Net Version</p><p></p><p>&lt;MetadataType(GetType(Movie.MovieMetaData))&gt;</p><p>Partial Public Class Movie</p><p>    Class MovieMetaData</p><p>        &lt;Required(ErrorMessage:=&quot;Titles are required&quot;)&gt;</p><p>        Public Property Title As String</p><p>    End Class</p><p>End Class</p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/FMastro.jpg?forceidenticon=false&amp;dt=635051580000000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by Rabid</title><link>http://www.asp.net/mvc/tutorials/older-versions/getting-started-with-mvc/getting-started-with-mvc-part7</link><pubDate>Fri, 22 Oct 2010 15:17:28 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000010718</guid><description><![CDATA[ <p>I am getting the following error on this part of the tutorial.  This happens when leaving the field blank.  How do I go about fixing this?</p><p></p><p></p><p></p><p>System.Data.ConstraintException was unhandled by user code</p><p>  Message=This property cannot be set to a null value.</p><p>  Source=System.Data.Entity</p><p>  StackTrace:</p><p>       at System.Data.EntityUtil.ThrowPropertyIsNotNullable()</p><p>       at System.Data.Objects.DataClasses.StructuralObject.SetValidValue(String value, Boolean isNullable)</p><p>       at Movies.Models.Movie.set_Movie_Name(String value) in </p><p></p><p>line 179</p><p>  InnerException: </p><p></p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/Rabid.jpg?forceidenticon=false&amp;dt=635051580000000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by alexkillen</title><link>http://www.asp.net/mvc/tutorials/older-versions/getting-started-with-mvc/getting-started-with-mvc-part7</link><pubDate>Thu, 28 Oct 2010 10:53:16 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000010757</guid><description><![CDATA[ <p>Solution for ConstraintException when Title is empty:</p><p></p><p>[Required(ErrorMessage = &quot;A Title is required&quot;)]</p><p>[DisplayFormat(ConvertEmptyStringToNull = false)]</p><p>public string Title { get; set; }</p><p></p><p>For some reason empty strings are being converted into null. Since the Title column in the Movie table in the database in NOT nullable, the Movie class that was generated (found in Movies.Designer.cs) has had the following attribute assigned to the Title property:</p><p>[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]</p><p></p><p>But we can prevent the empty string from being converted using the DisplayFormat attribute:</p><p>[DisplayFormat(ConvertEmptyStringToNull = false)]</p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/alexkillen.jpg?forceidenticon=false&amp;dt=635051580000000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by alexkillen</title><link>http://www.asp.net/mvc/tutorials/older-versions/getting-started-with-mvc/getting-started-with-mvc-part7</link><pubDate>Thu, 28 Oct 2010 11:36:16 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000010759</guid><description><![CDATA[ <p>The DisplayFormat attribute can also be used to fix the same ConstraintException problem with Genre, since it is a String. Add the following code to the MovieMetaData class:</p><p></p><p>[DisplayFormat(ConvertEmptyStringToNull = false)]</p><p>public string Genre { get; set; }</p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/alexkillen.jpg?forceidenticon=false&amp;dt=635051580000000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by rockin2009</title><link>http://www.asp.net/mvc/tutorials/older-versions/getting-started-with-mvc/getting-started-with-mvc-part7</link><pubDate>Mon, 01 Nov 2010 05:49:02 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000010787</guid><description><![CDATA[ <p>&lt;asp:Content ID=&quot;Content2&quot; ContentPlaceHolderID=&quot;MainContent&quot; runat=&quot;server&quot;&gt;</p><p></p><p>    &lt;h2&gt;Create&lt;/h2&gt;</p><p>    &lt;script src=&quot;../../Scripts/MicrosoftAjax.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</p><p>    &lt;script src=&quot;../../Scripts/MicrosoftMvcValidation.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</p><p>    &lt;% Html.EnableClientValidation() ; %&gt;</p><p>    &lt;% using (Html.BeginForm()) {%&gt;</p><p>        &lt;%: Html.ValidationSummary(true) %&gt;</p><p></p><p>        &lt;fieldset&gt;</p><p>            &lt;legend&gt;Fields&lt;/legend&gt;</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/rockin2009.jpg?forceidenticon=false&amp;dt=635051580000000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by rockin2009</title><link>http://www.asp.net/mvc/tutorials/older-versions/getting-started-with-mvc/getting-started-with-mvc-part7</link><pubDate>Mon, 01 Nov 2010 05:50:55 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000010788</guid><description><![CDATA[ <p>it worked fine the jscripts...add like the above</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/rockin2009.jpg?forceidenticon=false&amp;dt=635051580000000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by warez_willy</title><link>http://www.asp.net/mvc/tutorials/older-versions/getting-started-with-mvc/getting-started-with-mvc-part7</link><pubDate>Mon, 08 Nov 2010 19:34:38 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000010874</guid><description><![CDATA[ <p>Groovy!</p><p></p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/warez_willy.jpg?forceidenticon=false&amp;dt=635051580000000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by JomyKanjal</title><link>http://www.asp.net/mvc/tutorials/older-versions/getting-started-with-mvc/getting-started-with-mvc-part7</link><pubDate>Wed, 10 Nov 2010 14:35:51 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000010906</guid><description><![CDATA[ <p>Javascript insertion looks like this.</p><p></p><p> &lt;script src=&quot;../../Scripts/MicrosoftAjax.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</p><p>    &lt;script src=&quot;../../Scripts/MicrosoftMvcValidation.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</p><p></p><p>not </p><p></p><p>&lt;script src=&quot;/Scripts/MicrosoftAjax.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</p><p>&lt;script src=&quot;/Scripts/MicrosoftMvcValidation.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/JomyKanjal.jpg?forceidenticon=false&amp;dt=635051580000000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item></channel></rss>