<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>Iteration #3 – Add form validation</title><link>http://asp.net</link><pubDate>Mon, 11 Apr 2011 11:28:39 GMT</pubDate><generator>umbraco</generator><description>Comments for Iteration #3 – Add form validation</description><language>en</language><atom:link href="http://asp.net/rss/comments/27616" rel="self" type="application/rss+xml" /><item><title>Comment Posted by hlpearl</title><link>http://asp.net/mvc/tutorials/older-versions/contact-manager/iteration-3-add-form-validation-vb</link><pubDate>Mon, 11 Apr 2011 11:08:48 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000012762</guid><description><![CDATA[ <p>Protected Sub ValidateContact(contactToValidate As Contact)</p><p>        If contactToValidate.FirstName.Trim().Length = 0 Then</p><p>            ModelState.AddModelError(&quot;FirstName&quot;, &quot;First name is required.&quot;)</p><p>It appears to me, this test will ALWAYS fail with an &quot;Object reference not set to an instance of an object&quot; with the trim added to the variable name. Granted the trim needs to be added, but as written it appears to fail.</p><p>        End If</p><p></p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/hlpearl.jpg?forceidenticon=false&amp;dt=635050879800000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by hlpearl</title><link>http://asp.net/mvc/tutorials/older-versions/contact-manager/iteration-3-add-form-validation-vb</link><pubDate>Mon, 11 Apr 2011 11:28:39 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000012764</guid><description><![CDATA[ <p>As, written, when the FirstName is Null, the statement fails with an &quot;Object reference not set to an instance of an object&quot;. But when changes to statemets as follows:</p><p></p><p>Function Create(&lt;Bind(Exclude:=&quot;Id&quot;)&gt; ByVal contactToCreate As Contact) As ActionResult</p><p>            &#39; Validation(logic)</p><p>            If Len(contactToCreate.FirstName) = 0 Then</p><p>                ModelState.AddModelError(&quot;FirstName&quot;, &quot;First name is required.&quot;)</p><p>            ElseIf Len(contactToCreate.FirstName.Trim()) &gt; 0 Then</p><p>            Else</p><p>                ModelState.AddModelError(&quot;FirstName&quot;, &quot;First name is required.&quot;)</p><p>            End If</p><p></p><p>It works. If someones sees a different and/or better, please let me know?</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/hlpearl.jpg?forceidenticon=false&amp;dt=635050879800000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item></channel></rss>