<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>Performing Simple Validation</title><link>http://asp.net</link><pubDate>Tue, 02 Aug 2011 12:58:10 GMT</pubDate><generator>umbraco</generator><description>Comments for Performing Simple Validation</description><language>en</language><atom:link href="http://asp.net/rss/comments/27580" rel="self" type="application/rss+xml" /><item><title>Comment Posted by zulfiqar.langah</title><link>http://asp.net/mvc/tutorials/older-versions/models-(data)/performing-simple-validation-cs</link><pubDate>Tue, 25 May 2010 02:59:27 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000008911</guid><description><![CDATA[ <p>Good Article </p><p>This things which i want.</p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/zulfiqar.langah.jpg?forceidenticon=false&amp;dt=635048702400000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by porkchop2k</title><link>http://asp.net/mvc/tutorials/older-versions/models-(data)/performing-simple-validation-cs</link><pubDate>Wed, 16 Jun 2010 10:16:43 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000009116</guid><description><![CDATA[ <p>Listing 1 appears to be incomplete.</p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/porkchop2k.jpg?forceidenticon=false&amp;dt=635048702400000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by talktoanil</title><link>http://asp.net/mvc/tutorials/older-versions/models-(data)/performing-simple-validation-cs</link><pubDate>Mon, 06 Sep 2010 13:43:39 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000010138</guid><description><![CDATA[ <p>yeah, many of the listing are not proper. </p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/talktoanil.jpg?forceidenticon=false&amp;dt=635048702400000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by thebigbull</title><link>http://asp.net/mvc/tutorials/older-versions/models-(data)/performing-simple-validation-cs</link><pubDate>Tue, 16 Nov 2010 12:13:45 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000010964</guid><description><![CDATA[ <p>Agreed you took a short cut, do not recommend that controller should contain validation logic. </p><p>As a beginner I will have to look around for more examples on how to perform validation on a simple asp.net mvc app. come on....u cud have avoided the shortcut to help us save time.</p><p>Thanks anyway :)</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/thebigbull.jpg?forceidenticon=false&amp;dt=635048702400000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by Rob Grainger</title><link>http://asp.net/mvc/tutorials/older-versions/models-(data)/performing-simple-validation-cs</link><pubDate>Wed, 24 Nov 2010 06:26:28 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000011043</guid><description><![CDATA[ <p>Listing 1 seems to be truncated</p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/Rob%20Grainger.jpg?forceidenticon=false&amp;dt=635048702400000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by flouzje</title><link>http://asp.net/mvc/tutorials/older-versions/models-(data)/performing-simple-validation-cs</link><pubDate>Fri, 04 Feb 2011 03:58:04 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000011922</guid><description><![CDATA[ <p>How do I access the modelstate in the model itself ?</p><p>Validation should happen there, not in the controller... Right ?</p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/flouzje.jpg?forceidenticon=false&amp;dt=635048702400000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by flouzje</title><link>http://asp.net/mvc/tutorials/older-versions/models-(data)/performing-simple-validation-cs</link><pubDate>Fri, 04 Feb 2011 04:00:14 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000011923</guid><description><![CDATA[ <p>Already found it : <a rel="nofollow" href="http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx" target="_blank">weblogs.asp.net/</a></p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/flouzje.jpg?forceidenticon=false&amp;dt=635048702400000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by flouzje</title><link>http://asp.net/mvc/tutorials/older-versions/models-(data)/performing-simple-validation-cs</link><pubDate>Fri, 04 Feb 2011 04:00:33 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000011924</guid><description><![CDATA[ <p>google : validation in asp.net mvc</p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/flouzje.jpg?forceidenticon=false&amp;dt=635048702400000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by skotl</title><link>http://asp.net/mvc/tutorials/older-versions/models-(data)/performing-simple-validation-cs</link><pubDate>Mon, 11 Apr 2011 08:12:35 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000012759</guid><description><![CDATA[ <p>Good article, thanks. To those pointing out that the &quot;listings are incomplete&quot;, they are just supposed to be code fragments!</p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/skotl.jpg?forceidenticon=false&amp;dt=635048702400000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by bkinc</title><link>http://asp.net/mvc/tutorials/older-versions/models-(data)/performing-simple-validation-cs</link><pubDate>Tue, 02 Aug 2011 12:58:10 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000013890</guid><description><![CDATA[ <p>Cutting and pasting that does not work in MVC3. To get the extension to work, I had to create a class file:</p><p>using System;</p><p>using System.Collections.Generic;</p><p>using System.Linq;</p><p>using System.Web;</p><p>using System.Web.Mvc;</p><p></p><p>namespace incMvcSite.Classes {</p><p>    public static class HtmlPrefixScopeExtensions {</p><p>        public static IDisposable BeginHtmlFieldPrefixScope(this HtmlHelper html, string htmlFieldPrefix) {</p><p>            return new HtmlFieldPrefixScope(html.ViewData.TemplateInfo, htmlFieldPrefix);</p><p>        }</p><p></p><p>        private class HtmlFieldPrefixScope : IDisposable {</p><p>            private readonly TemplateInfo templateInfo;</p><p>            private readonly string previousHtmlFieldPrefix;</p><p></p><p>            public HtmlFieldPrefixScope(TemplateInfo templateInfo, string htmlFieldPrefix) {</p><p>                this.templateInfo = templateInfo;</p><p></p><p>                previousHtmlFieldPrefix = templateInfo.HtmlFieldPrefix;</p><p>                templateInfo.HtmlFieldPrefix = htmlFieldPrefix;</p><p>            }</p><p></p><p>            public void Dispose() {</p><p>                templateInfo.HtmlFieldPrefix = previousHtmlFieldPrefix;</p><p>            }</p><p>        }</p><p>    }</p><p>}</p><p>In the Razor (.cshtml) file, I added the following:</p><p>@using incMvcSite.Classes</p><p>@using(Html.BeginHtmlFieldPrefixScope(&quot;Permission&quot;)) {</p><p>    </p><p>        Permission</p><p></p><p>        // The Html.EditorFor&#39;s would go here...</p><p>    </p><p>}</p><p>Notice the using to bring me extension class into scope. That allows the second using line to work.</p><p>Now the problem is that when posting back, the object is not updated. In my controller, I used a second parameter to specify my prefix:</p><p>TryUpdateModel(modelUser.Permission, &quot;Permission&quot;);</p><p>This added the prefix to all field in the HTML, and the TryUpdateModel loaded the object with prefixed control names. Now you can properly namespace your controls for embedded edit lists, and for partial views of models with the same property names.</p><p></p><p>Shawn Zernik</p><p>Internetwork Consulting</p><p><a rel="nofollow" href="http://www.internetworkconsulting.net" target="_blank">www.internetworkconsulting.net</a></p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/bkinc.jpg?forceidenticon=false&amp;dt=635048702400000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item></channel></rss>