<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: ASP.NET MVC Quick Tip: Check Data Annotations from code</title>
	<atom:link href="http://www.minddriven.de/index.php/technology/dot-net/web/asp-net-mvc/check-data-annotations-from-code/feed" rel="self" type="application/rss+xml" />
	<link>http://www.minddriven.de/index.php/technology/dot-net/web/asp-net-mvc/check-data-annotations-from-code</link>
	<description>Matthias Jauernig -- .NET technology, architecture and design</description>
	<lastBuildDate>Thu, 02 Feb 2012 06:42:23 +0100</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
	<item>
		<title>By: Charles Boyung</title>
		<link>http://www.minddriven.de/index.php/technology/dot-net/web/asp-net-mvc/check-data-annotations-from-code/comment-page-1#comment-5896</link>
		<dc:creator>Charles Boyung</dc:creator>
		<pubDate>Thu, 17 Jun 2010 18:32:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.minddriven.de/?p=841#comment-5896</guid>
		<description>Your entire last section is wholly unnecessary (as far back as early February with MVC2 RC2). You state: &quot;That means only the Data Annotations on the posted form values are checked, but not other properties which are perhaps defined on the model class, but missing in the form values.&quot;

But MVC2 Data Annotation Validation now does Model Validation not Input Validation. Check out http://weblogs.asp.net/scottgu/archive/2010/02/05/asp-net-mvc-2-release-candidate-2-now-available.aspx</description>
		<content:encoded><![CDATA[<p>Your entire last section is wholly unnecessary (as far back as early February with MVC2 RC2). You state: &#8220;That means only the Data Annotations on the posted form values are checked, but not other properties which are perhaps defined on the model class, but missing in the form values.&#8221;</p>
<p>But MVC2 Data Annotation Validation now does Model Validation not Input Validation. Check out <a href="http://weblogs.asp.net/scottgu/archive/2010/02/05/asp-net-mvc-2-release-candidate-2-now-available.aspx" rel="nofollow">http://weblogs.asp.net/scottgu/archive/2010/02/05/asp-net-mvc-2-release-candidate-2-now-available.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JoeReynolds</title>
		<link>http://www.minddriven.de/index.php/technology/dot-net/web/asp-net-mvc/check-data-annotations-from-code/comment-page-1#comment-5848</link>
		<dc:creator>JoeReynolds</dc:creator>
		<pubDate>Wed, 26 May 2010 03:03:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.minddriven.de/?p=841#comment-5848</guid>
		<description>If ArticleName does not allow NULL in db and the Required attribute is removed from the Class, then validation still returns an error message on the form when submitted. The error returned is:
The value &#039;&#039; is invalid.
However, this happens with or without using your code above.

If ArticleName allows NULL then the item is added to db with a null value, and that can cause major problems unless SELECT commands include a ISNULL value.

As to what I want to test, it is to test something live in a way some malicious user might do so as to see what the code you provided does.

At any rate, I don&#039;t want to impose on your time and thanks for your replies.</description>
		<content:encoded><![CDATA[<p>If ArticleName does not allow NULL in db and the Required attribute is removed from the Class, then validation still returns an error message on the form when submitted. The error returned is:<br />
The value &#8221; is invalid.<br />
However, this happens with or without using your code above.</p>
<p>If ArticleName allows NULL then the item is added to db with a null value, and that can cause major problems unless SELECT commands include a ISNULL value.</p>
<p>As to what I want to test, it is to test something live in a way some malicious user might do so as to see what the code you provided does.</p>
<p>At any rate, I don&#8217;t want to impose on your time and thanks for your replies.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MatthiasJ</title>
		<link>http://www.minddriven.de/index.php/technology/dot-net/web/asp-net-mvc/check-data-annotations-from-code/comment-page-1#comment-5847</link>
		<dc:creator>MatthiasJ</dc:creator>
		<pubDate>Tue, 25 May 2010 20:36:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.minddriven.de/?p=841#comment-5847</guid>
		<description>Hi Joe, 

I&#039;m not sure WHAT you want to test. Do you want to test that the model validation is performed and produces an invalid ModelState when the ArticleName is null/empty? Of course your test has to invoke the according controller action with the invalid model entity. Afterwards you can check if the ModelState was invalid (thus the model validation was performed correctly). I hope you know how to test MVC controllers, else there are some great articles on the web.</description>
		<content:encoded><![CDATA[<p>Hi Joe, </p>
<p>I&#8217;m not sure WHAT you want to test. Do you want to test that the model validation is performed and produces an invalid ModelState when the ArticleName is null/empty? Of course your test has to invoke the according controller action with the invalid model entity. Afterwards you can check if the ModelState was invalid (thus the model validation was performed correctly). I hope you know how to test MVC controllers, else there are some great articles on the web.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JoeReynolds</title>
		<link>http://www.minddriven.de/index.php/technology/dot-net/web/asp-net-mvc/check-data-annotations-from-code/comment-page-1#comment-5846</link>
		<dc:creator>JoeReynolds</dc:creator>
		<pubDate>Tue, 25 May 2010 20:26:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.minddriven.de/?p=841#comment-5846</guid>
		<description>Thanks for the prompt response. I&#039;m not sure how to manipulate the model to produce a valid test.

Assume a single input of &quot;ArticleName&quot; -- -- 35 varchar in database,
and 
field input of

Html.TextBoxFor(model =&gt; model.articleToCreate.ArticleName, new { style = &quot;width: 235px;&quot; })

ArticleName has a Required attribute in my Class.

How could this be tested?</description>
		<content:encoded><![CDATA[<p>Thanks for the prompt response. I&#8217;m not sure how to manipulate the model to produce a valid test.</p>
<p>Assume a single input of &#8220;ArticleName&#8221; &#8212; &#8211; 35 varchar in database,<br />
and<br />
field input of</p>
<p>Html.TextBoxFor(model =&gt; model.articleToCreate.ArticleName, new { style = &#8220;width: 235px;&#8221; })</p>
<p>ArticleName has a Required attribute in my Class.</p>
<p>How could this be tested?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MatthiasJ</title>
		<link>http://www.minddriven.de/index.php/technology/dot-net/web/asp-net-mvc/check-data-annotations-from-code/comment-page-1#comment-5845</link>
		<dc:creator>MatthiasJ</dc:creator>
		<pubDate>Tue, 25 May 2010 19:14:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.minddriven.de/?p=841#comment-5845</guid>
		<description>Of course you can test itby invoking a controller action with model entities you assume. Then you can look if the model state is valid or invalid depending on what you expect to get from your annotated model. Base controller should be no problem if the concrete controller still has the MVC &quot;Controller&quot; class in the inheritance hierarchy.</description>
		<content:encoded><![CDATA[<p>Of course you can test itby invoking a controller action with model entities you assume. Then you can look if the model state is valid or invalid depending on what you expect to get from your annotated model. Base controller should be no problem if the concrete controller still has the MVC &#8220;Controller&#8221; class in the inheritance hierarchy.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JoeReynolds</title>
		<link>http://www.minddriven.de/index.php/technology/dot-net/web/asp-net-mvc/check-data-annotations-from-code/comment-page-1#comment-5843</link>
		<dc:creator>JoeReynolds</dc:creator>
		<pubDate>Tue, 25 May 2010 18:34:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.minddriven.de/?p=841#comment-5843</guid>
		<description>I&#039;ve implemented this and all my post code still works as before. That&#039;s good, but is there some way to test it? Also, my controllers all inherit from a base controller so perhaps the code is doing nothing.</description>
		<content:encoded><![CDATA[<p>I&#8217;ve implemented this and all my post code still works as before. That&#8217;s good, but is there some way to test it? Also, my controllers all inherit from a base controller so perhaps the code is doing nothing.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

