<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>ASP.NET MVC</title>
        <link>http://blogs.imeta.co.uk/HHariri/category/95.aspx</link>
        <description>ASP.NET MVC</description>
        <language>en-GB</language>
        <copyright>Hadi Hariri </copyright>
        <generator>Subtext Version 2.1.1.1</generator>
        <item>
            <title>List my controllers for me&amp;hellip;</title>
            <link>http://blogs.imeta.co.uk/HHariri/archive/2009/10/10/list-my-controllers-for-mehellip.aspx</link>
            <description>&lt;p&gt; &lt;/p&gt;  &lt;p&gt;Nuff said!&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/IntellisenseonControllers_9AF0/image_2.png" rel="lightbox"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/IntellisenseonControllers_9AF0/image_thumb.png" width="527" height="111" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Really liking Resharper 5.&lt;/p&gt;&lt;img src="http://blogs.imeta.co.uk/HHariri/aggbug/779.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Hadi Hariri </dc:creator>
            <guid>http://blogs.imeta.co.uk/HHariri/archive/2009/10/10/list-my-controllers-for-mehellip.aspx</guid>
            <pubDate>Sat, 10 Oct 2009 09:02:42 GMT</pubDate>
            <comments>http://blogs.imeta.co.uk/HHariri/archive/2009/10/10/list-my-controllers-for-mehellip.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.imeta.co.uk/HHariri/comments/commentRss/779.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.imeta.co.uk/HHariri/services/trackbacks/779.aspx</trackback:ping>
        </item>
        <item>
            <title>Resharper 5 support for MVC</title>
            <link>http://blogs.imeta.co.uk/HHariri/archive/2009/10/10/resharper-5-support-for-mvc.aspx</link>
            <description>&lt;p&gt; &lt;/p&gt;  &lt;p&gt;Resharper 5 has a couple of new features for MVC that can make your life somewhat easier. Take a look at the following screenshot:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/Resharper5supportforMVC_412/image_2.png" rel="lightbox"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/Resharper5supportforMVC_412/image_thumb.png" width="582" height="136" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;That’s inside an ASPX ViewPage. The first thing is the &lt;strong&gt;“Abouta”&lt;/strong&gt; underlined in blue. The hint tells me that this action does not exist. &lt;strong&gt;“Home”&lt;/strong&gt; on the other hand, which corresponds to a controller is underlined, meaning you can navigate to it from there (ctrl+left mouse click).&lt;/p&gt;  &lt;p&gt;In the case of the action not existing, if we haven’t spelt it wrong, we can ask Resharper to create it for us:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/Resharper5supportforMVC_412/image_4.png" rel="lightbox"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/Resharper5supportforMVC_412/image_thumb_1.png" width="578" height="145" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;which generates the corresponding action in the controller:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/Resharper5supportforMVC_412/image_6.png" rel="lightbox"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/Resharper5supportforMVC_412/image_thumb_2.png" width="581" height="158" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Simple, yet very productive!&lt;/p&gt;&lt;img src="http://blogs.imeta.co.uk/HHariri/aggbug/778.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Hadi Hariri </dc:creator>
            <guid>http://blogs.imeta.co.uk/HHariri/archive/2009/10/10/resharper-5-support-for-mvc.aspx</guid>
            <pubDate>Fri, 09 Oct 2009 22:18:59 GMT</pubDate>
            <comments>http://blogs.imeta.co.uk/HHariri/archive/2009/10/10/resharper-5-support-for-mvc.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://blogs.imeta.co.uk/HHariri/comments/commentRss/778.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.imeta.co.uk/HHariri/services/trackbacks/778.aspx</trackback:ping>
        </item>
        <item>
            <title>The Principle of Least Surprise</title>
            <link>http://blogs.imeta.co.uk/HHariri/archive/2009/10/09/the-principle-of-least-surprise.aspx</link>
            <description>&lt;p&gt; &lt;/p&gt;  &lt;p&gt;I’m having a discussion on the ASP.NET MVC forums with one of the guys from the ASP.NET team in regard to the Data Annotations in MVC 2 and I’m not sure I agree with him. Here’s an issue &lt;a href="http://devlicio.us/blogs/casey/"&gt;Jak&lt;/a&gt; and I have run into: &lt;/p&gt;  &lt;p&gt;In MVC 2 there’s a new Html Helper named &lt;em&gt;EditorForModel(); &lt;/em&gt;that renders out a form based on the properties of your model, along with the validation messages, labels, etc. So something like this:&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;div class="csharpcode"&gt;   &lt;pre class="alt"&gt;   &amp;lt;% &lt;span class="kwrd"&gt;using&lt;/span&gt; (Html.BeginForm()) {%&amp;gt;&lt;/pre&gt;

  &lt;pre&gt; &lt;/pre&gt;

  &lt;pre class="alt"&gt;        &amp;lt;%=Html.EditorForModel() %&amp;gt;     &lt;/pre&gt;

  &lt;pre&gt;            &amp;lt;p&amp;gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;                &amp;lt;input type=&lt;span class="str"&gt;"submit"&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;=&lt;span class="str"&gt;"Save"&lt;/span&gt; /&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;            &amp;lt;/p&amp;gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &amp;lt;% } %&amp;gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;you’d get something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/ThePrincipleofLeastSurprise_AE22/image_2.png" rel="lightbox"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/ThePrincipleofLeastSurprise_AE22/image_thumb.png" width="373" height="230" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;If you want to do individual fields and thus have finer control, you can use the &lt;em&gt;EditorFor&lt;/em&gt; helper, passing in a property name. In other words, the previous could be also rendered as:&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;    &amp;lt;% &lt;span class="kwrd"&gt;using&lt;/span&gt; (Html.BeginForm()) {%&amp;gt;&lt;/pre&gt;

  &lt;pre&gt; &lt;/pre&gt;

  &lt;pre class="alt"&gt;        &lt;/pre&gt;

  &lt;pre&gt;   &amp;lt;%=Html.EditorFor( model =&amp;gt; model.FirstName) %&amp;gt; &lt;/pre&gt;

  &lt;pre class="alt"&gt;   &amp;lt;%=Html.EditorFor( model =&amp;gt; model.LastName) %&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;   &amp;lt;%=Html.EditorFor( model =&amp;gt; model.Email) %&amp;gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;        &lt;/pre&gt;

  &lt;pre&gt;            &amp;lt;p&amp;gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;                &amp;lt;input type=&lt;span class="str"&gt;"submit"&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;=&lt;span class="str"&gt;"Save"&lt;/span&gt; /&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;            &amp;lt;/p&amp;gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &amp;lt;% } %&amp;gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p /&gt;&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;but this time you don’t get the labels: &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/ThePrincipleofLeastSurprise_AE22/image_4.png" rel="lightbox"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/ThePrincipleofLeastSurprise_AE22/image_thumb_1.png" width="393" height="247" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The problem however is that you lose something else: the Validation messages. If you have client-side validation enabled, the previous ASPX file generates a pretty much useless call to the &lt;em&gt;EnableClientValidation&lt;/em&gt; JS function: &lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;EnableClientValidation({&lt;span class="str"&gt;"Fields"&lt;/span&gt;:[],&lt;span class="str"&gt;"FormId"&lt;/span&gt;:&lt;span class="str"&gt;"form0"&lt;/span&gt;}, &lt;span class="kwrd"&gt;null&lt;/span&gt;);&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;as opposed to: &lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;div class="csharpcode"&gt;
    &lt;div class="csharpcode"&gt;
      &lt;pre class="alt"&gt;EnableClientValidation({&lt;span class="str"&gt;"Fields"&lt;/span&gt;:[{&lt;span class="str"&gt;"FieldName"&lt;/span&gt;:&lt;span class="str"&gt;"FirstName"&lt;/span&gt;,&lt;span class="str"&gt;"ValidationRules"&lt;/span&gt;:[{&lt;span class="str"&gt;"ErrorMessage"&lt;/span&gt;:&lt;span class="str"&gt;"First name is required"&lt;/span&gt;,&lt;span class="str"&gt;"ValidationParameters"&lt;/span&gt;:....&lt;/pre&gt;

      &lt;pre&gt; &lt;/pre&gt;

      &lt;pre class="alt"&gt;// rest omitted &lt;span class="kwrd"&gt;for&lt;/span&gt; brevity&lt;/pre&gt;
    &lt;/div&gt;
    &lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;&lt;/div&gt;
  &lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;&lt;/div&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;The result of course is that client-validation doesn’t work (and from what I’ve heard causes JS errors in some browsers). &lt;/p&gt;

&lt;p&gt;The solution to this is to explicitly add a Validation Message, like so:&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&amp;lt;%=Html.ValidationMessage(&lt;span class="str"&gt;"FirstName"&lt;/span&gt;)%&amp;gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p /&gt;&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;Now I understand that &lt;em&gt;EditorFor &lt;/em&gt;is for fine-tuning and there is a corresponding &lt;em&gt;LabelFor&lt;/em&gt; (although a &lt;em&gt;ValidationFor &lt;/em&gt;doesn’t exist yet), but my main concern here is that it’s breaking the principle of least surprise from an API perspective. &lt;/p&gt;

&lt;p&gt;For me, the only difference between &lt;em&gt;EditorFor&lt;/em&gt; and &lt;em&gt;EditorForModel&lt;/em&gt; should be that in the first I specify a property name explicitly whereas in the latter it just assumes the whole model. Nothing is telling me by the name of the method that the second does a whole bunch more of magic. &lt;/p&gt;

&lt;p&gt;One solution is for &lt;em&gt;EditorFor&lt;/em&gt; to be renamed to something else if it’s ONLY going to provide the input box (be it a text area, checkbox, radio group, etc..).&lt;/p&gt;

&lt;p&gt;Thoughts?&lt;/p&gt;&lt;img src="http://blogs.imeta.co.uk/HHariri/aggbug/777.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Hadi Hariri </dc:creator>
            <guid>http://blogs.imeta.co.uk/HHariri/archive/2009/10/09/the-principle-of-least-surprise.aspx</guid>
            <pubDate>Fri, 09 Oct 2009 10:23:51 GMT</pubDate>
            <comments>http://blogs.imeta.co.uk/HHariri/archive/2009/10/09/the-principle-of-least-surprise.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.imeta.co.uk/HHariri/comments/commentRss/777.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.imeta.co.uk/HHariri/services/trackbacks/777.aspx</trackback:ping>
        </item>
        <item>
            <title>Problem with Client-Side Validation in MVC 2</title>
            <link>http://blogs.imeta.co.uk/HHariri/archive/2009/10/07/problem-with-client-side-validation-in-mvc-2.0.aspx</link>
            <description>&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;[Note: This post applies to ASP.NET MVC 2, Preview 2.0]&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Today while doing the demo for the &lt;a href="http://hadihariri.com/blogengine/post/2009/10/06/Client-Side-Validation-in-MVC-20.aspx"&gt;previous post&lt;/a&gt;, I ran into an issue where the Javascript code for the client-side validation (the call to &lt;em&gt;EnableClientValidation &lt;/em&gt;) was not being output during the form rendering. &lt;/p&gt;
&lt;p&gt;Take a look at the following two snippets:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;First:&lt;/strong&gt;&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;    &amp;lt;% Html.BeginForm();%&amp;gt;&lt;/pre&gt;
&lt;pre&gt; &lt;/pre&gt;
&lt;pre class="alt"&gt;        &amp;lt;%=Html.EditorForModel() %&amp;gt;     &lt;/pre&gt;
&lt;pre&gt;            &amp;lt;p&amp;gt;&lt;/pre&gt;
&lt;pre class="alt"&gt;                &amp;lt;input type=&lt;span class="str"&gt;"submit"&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;=&lt;span class="str"&gt;"Save"&lt;/span&gt; /&amp;gt;&lt;/pre&gt;
&lt;pre&gt;            &amp;lt;/p&amp;gt;&lt;/pre&gt;
&lt;pre class="alt"&gt;    &amp;lt;% Html.EndForm(); %&amp;gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Second:&lt;/strong&gt;&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;  &amp;lt;% &lt;span class="kwrd"&gt;using&lt;/span&gt; (Html.BeginForm()) {%&amp;gt;&lt;/pre&gt;
&lt;pre&gt; &lt;/pre&gt;
&lt;pre class="alt"&gt;        &amp;lt;%=Html.EditorForModel() %&amp;gt;     &lt;/pre&gt;
&lt;pre&gt;            &amp;lt;p&amp;gt;&lt;/pre&gt;
&lt;pre class="alt"&gt;                &amp;lt;input type=&lt;span class="str"&gt;"submit"&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;=&lt;span class="str"&gt;"Save"&lt;/span&gt; /&amp;gt;&lt;/pre&gt;
&lt;pre&gt;            &amp;lt;/p&amp;gt;&lt;/pre&gt;
&lt;pre class="alt"&gt;    &amp;lt;% } %&amp;gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;See the difference? The latter is using the &lt;em&gt;using &lt;/em&gt;statement. In my previous post I’m using this option and all works well. However, if you go with the first option, the Javascript call will not be output. The reason for this (after debugging the source) is that the call to make this happen takes place in the &lt;em&gt;Dispose &lt;/em&gt;method of the &lt;em&gt;MvcForm&lt;/em&gt;. Explicitly calling &lt;em&gt;Html.EndForm&lt;/em&gt; won’t cause this to take place. &lt;/p&gt;
&lt;p&gt;I’ve talked to Mathew from the QA team, and &lt;a href="http://twitter.com/osbornm/status/4689501425"&gt;he’s confirmed it’s a known issue&lt;/a&gt;. I think the output of the JS code should ideally be decoupled from the form construction. For instance, If I were to use a manual form tag, this wouldn’t work either [I’ve haven’t given it that much thought either].&lt;/p&gt;
&lt;p&gt;In the meantime, if you want client-side validation, make sure you use the second option.&lt;/p&gt;&lt;img src="http://blogs.imeta.co.uk/HHariri/aggbug/775.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Hadi Hariri </dc:creator>
            <guid>http://blogs.imeta.co.uk/HHariri/archive/2009/10/07/problem-with-client-side-validation-in-mvc-2.0.aspx</guid>
            <pubDate>Wed, 07 Oct 2009 19:35:38 GMT</pubDate>
            <comments>http://blogs.imeta.co.uk/HHariri/archive/2009/10/07/problem-with-client-side-validation-in-mvc-2.0.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://blogs.imeta.co.uk/HHariri/comments/commentRss/775.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.imeta.co.uk/HHariri/services/trackbacks/775.aspx</trackback:ping>
        </item>
        <item>
            <title>Upcoming talks</title>
            <link>http://blogs.imeta.co.uk/HHariri/archive/2009/09/09/upcoming-talks-again.aspx</link>
            <description>&lt;p&gt; &lt;/p&gt;  &lt;p&gt;Start of the “conference season” again and I’ll be doing a tour of a few countries and places. Hope to meet up with some of you at some place and time. This time I’ll try and have all sessions ready so I can spend my time more productively at the bar/restaurant&lt;/p&gt;  &lt;p&gt;- 21st to 25th September at &lt;a href="http://www.basta.net"&gt;BASTA&lt;/a&gt;! in Germany. Talks on ASP.NET MVC, jQuery, TDD, Design Principles.&lt;/p&gt;  &lt;p&gt;- 27th to 30th September at &lt;a href="http://entwicklerkonferenz.de"&gt;Entwickler Konferenz&lt;/a&gt; in Germany. Talks on ASP.NET MVC, TDD.&lt;/p&gt;  &lt;p&gt;- 12th to 13th October at &lt;a href="http://www.devreach.com"&gt;DevReach&lt;/a&gt; in Bulgaria. Talks on ASP.NET MVC, Design Principles.&lt;/p&gt;  &lt;p&gt;- 16th to 17th October at TTT/&lt;a href="http://www.codecamp.es"&gt;CodeCamp&lt;/a&gt; in Tarragona. Talks on MEF and Design Principles.&lt;/p&gt;  &lt;p&gt;- 18th to 21st October at &lt;a href="http://www.sdc.nl"&gt;SDC&lt;/a&gt; in The Netherlands. Talks on ASP.NET MVC.&lt;/p&gt;  &lt;p&gt;- 29th October at Micrsoft in Madrid. Workshop on Design Principles (Link available soon)&lt;/p&gt;  &lt;p&gt;I’ve also pre-recorded 3 sessions for an online virtual conference on ASP.NET MVC, jQuery and Mocks, all in Delphi Prism and it’s happening right now on &lt;a href="http://conferences.embarcadero.com/coderage"&gt;CodeRage&lt;/a&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;-&lt;/p&gt;&lt;img src="http://blogs.imeta.co.uk/HHariri/aggbug/752.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Hadi Hariri </dc:creator>
            <guid>http://blogs.imeta.co.uk/HHariri/archive/2009/09/09/upcoming-talks-again.aspx</guid>
            <pubDate>Wed, 09 Sep 2009 12:29:56 GMT</pubDate>
            <comments>http://blogs.imeta.co.uk/HHariri/archive/2009/09/09/upcoming-talks-again.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.imeta.co.uk/HHariri/comments/commentRss/752.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.imeta.co.uk/HHariri/services/trackbacks/752.aspx</trackback:ping>
        </item>
        <item>
            <title>ASP.NET MVC 2 - Preview 1</title>
            <link>http://blogs.imeta.co.uk/HHariri/archive/2009/07/31/asp.net-mvc-2-preview-1.aspx</link>
            <description>&lt;p&gt;It's out. You can download it &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=d34f9eaa-fcbe-4e20-b2fd-a9a03de7d6dd&amp;amp;displaylang=en"&gt;from here&lt;/a&gt;. Some of the new things it includes ("extracted" from the readme for your convenience):&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;span style="font-weight: bold;"&gt;Areas&lt;/span&gt;: When creating larger ASP.NET MVC applications, you tend to create controllers and views that might be named the same but belong to different aspects of the application (for example you might have a HomeController for Customers and one for Administration). Areas allows you to create "sub-projects" inside your project to group these. &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt; &lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;[&lt;span style="font-weight: bold;"&gt;HttpPost&lt;/span&gt;]: Shortcut for putting [AcceptVerbs(HttpVerbs.Post)] &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt; &lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;span style="font-weight: bold;"&gt;DataAnnotations&lt;/span&gt;: The default model binder supports DataAnnotations for validation &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt; &lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;span style="font-weight: bold;"&gt;DefaultValueAttribte&lt;/span&gt;: For types of Int32, DateTime or Guid's you can now specify a default value on the action declaration to better comply with your routing patterns. &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt; &lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;span style="font-weight: bold;"&gt;Supprot for byte[] and Data.Linq.Binary&lt;/span&gt;: Default Model binder now supports these types. &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt; &lt;/p&gt;
&lt;ul style="font-weight: bold;"&gt;
    &lt;li&gt;API improvments &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt; &lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;span style="font-weight: bold;"&gt;Templated Helpers&lt;/span&gt;: Basically allows you to associate types to certain elements for display/editing. &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;                     &lt;/p&gt;
&lt;p&gt;The only breaking changes it seems is introduction of the &lt;em&gt;Area &lt;/em&gt;keyword and a signature change in DefaultControllerFactory. That means if you're using a custom controller factory for IoC for example (and if you're not, you should be), you'll need to update your app. &lt;/p&gt;
&lt;p&gt;There's nothing in the README regarding the inclusion of the strongly-typed helpers from the Futures assembly or any new strongly-typed Html Helpers for element rendering. Not sure if they are included in this assembly or might come in the next preview. &lt;/p&gt;
&lt;p&gt;Now to go play with it a little...&lt;/p&gt;&lt;img src="http://blogs.imeta.co.uk/HHariri/aggbug/735.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Hadi Hariri </dc:creator>
            <guid>http://blogs.imeta.co.uk/HHariri/archive/2009/07/31/asp.net-mvc-2-preview-1.aspx</guid>
            <pubDate>Fri, 31 Jul 2009 05:46:56 GMT</pubDate>
            <comments>http://blogs.imeta.co.uk/HHariri/archive/2009/07/31/asp.net-mvc-2-preview-1.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.imeta.co.uk/HHariri/comments/commentRss/735.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.imeta.co.uk/HHariri/services/trackbacks/735.aspx</trackback:ping>
        </item>
        <item>
            <title>If you&amp;rsquo;re going to provide RAD for ASP.NET MVC, change your thinking hat</title>
            <link>http://blogs.imeta.co.uk/HHariri/archive/2009/06/11/if-yoursquore-going-to-provide-rad-for-asp.net-mvc-change.aspx</link>
            <description>&lt;p&gt; &lt;/p&gt;  &lt;p&gt;ASP.NET MVC is not new. Ignoring the pattern for a moment, the way things work dates back to the days of CGI’s and ISAPI’s, where you had to role out pretty much everything by hand. You would get your data, format it and send it back to the browser, producing HTML. It wasn’t easy, but you did have one advantage. You had full control. &lt;/p&gt;  &lt;p&gt;Gradually, tools starting to emerge to bring some sort of “RADness” to this kind of development. I in particular, used a technology called WebBroker from Delphi; we had Actions, PageProducers (replaced tags at runtime in an HTML template) and our data. Same concept as ASP.NET MVC, same concept as MonoRail, and other frameworks. Despite still having to do a lot of things manually, it did prevent us from having to write repetitive and tedious code in many cases. &lt;/p&gt;  &lt;p&gt;Up to then, you had one requisite to develop web applications: &lt;strong&gt;you had to understand the web and the technology behind it.&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Traditional ASP.NET or ASP.NET WebForms came around, among other things, to solve this problem: allow the non-web developer to leverage their existing knowledge to port their applications to the web. This meant not having to know much about web technology and at the same time. ASP.NET WebForms provided a &lt;em&gt;powerful&lt;/em&gt; approach to web development: the concept of drag-n-drop that existed in WinForm applications. You could now take a control, drag it across to a form, set some properties and away you go: in minutes you had a web interface without having to even know what HTML meant. &lt;/p&gt;  &lt;p&gt;Now, I’m no fan of ASP.NET WebForms. Actually that’s not entirely true. I hate it, but I still admit that for some it has it’s attractiveness and has solved problems for many people and put food on the table for many developers. So it has it’s place and will continue to live on. &lt;/p&gt;  &lt;p&gt;I’m also not alone. There are others like me that don’t like ASP.NET WebForms. As such, when ASP.NET MVC came out, it gave us another technology, based on the ASP.NET stack, to  develop web applications.  Ignoring many of the differences and advantages it has over traditional ASP.NET, above all, it gave us control. As I always say, it put the &lt;strong&gt;web &lt;/strong&gt;back into &lt;strong&gt;web development&lt;/strong&gt;. &lt;/p&gt;  &lt;p&gt;As developers started to embrace this technology, questions started to arise about what kind of support there would be in terms of controls. Naturally, third party component vendors, those same ones that were providing support for traditional ASP.NET components, were being asked about this too. All those that I spoke to pretty much said the same thing, let’s wait and see. And it’s completely the right approach. There’s no point in investing a large amount of time and resources into supporting a new framework if you don’t know what the success of the framework will be, both in adoption, as well as commitment from the company behind it, in this case Microsoft. &lt;/p&gt;  &lt;p&gt;Now that ASP.NET MVC has been released, and there is a growing number of developers moving over from traditional ASP.NET, some companies are starting to develop a limited number of controls for ASP.NET MVC. I’m guessing that some of these companies are dipping their feet into the MVC waters to see what kind of success their components might have, before taking the big plunge.&lt;/p&gt;  &lt;p&gt;I’ve examined a few of these components. I’m not going to mention any names or give an examples, but suffice to say, that up to now, I don’t like what I see. And the reason is simple. Most of them are taking the wrong approach. They are thinking with their WebForms hat on. However, since there is no visual designer, they are using an immense amount of markup with custom tags to define their components. And many are mixing data, behavior and appearance in these markups. The problem with this approach is that it’s going down the same route that many ASP.NET MVC developers left behind from by moving away from traditional WebForms: rich-intelligent-know-it-all controls. I’m not going to show any code since I don’t want to single-out any specific control/company, but sample applications for many of these exist and you’re free to examine them for yourself.&lt;/p&gt;  &lt;p&gt;To summarize, trying to bring the same RAD controls that exist in WebForms over to ASP.NET MVC might not necessarily be correct thing to do. This is a different way to doing web development, a different mentality. And in my humble opinion, I think that this might backfire, since MVC developers mostly will not be too keen on this type of solution, the adoption rate for the components will be low and the component vendors behind them will throw in the towel. &lt;/p&gt;&lt;img src="http://blogs.imeta.co.uk/HHariri/aggbug/709.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Hadi Hariri </dc:creator>
            <guid>http://blogs.imeta.co.uk/HHariri/archive/2009/06/11/if-yoursquore-going-to-provide-rad-for-asp.net-mvc-change.aspx</guid>
            <pubDate>Thu, 11 Jun 2009 18:37:31 GMT</pubDate>
            <comments>http://blogs.imeta.co.uk/HHariri/archive/2009/06/11/if-yoursquore-going-to-provide-rad-for-asp.net-mvc-change.aspx#feedback</comments>
            <slash:comments>26</slash:comments>
            <wfw:commentRss>http://blogs.imeta.co.uk/HHariri/comments/commentRss/709.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.imeta.co.uk/HHariri/services/trackbacks/709.aspx</trackback:ping>
        </item>
        <item>
            <title>Second Part of ASP.NET MVC Alt.NET Hispano Talk available</title>
            <link>http://blogs.imeta.co.uk/HHariri/archive/2009/05/12/second-part-of-asp.net-mvc-alt.net-hispano-talk-avaiable.aspx</link>
            <description>&lt;p&gt; &lt;/p&gt;
&lt;p&gt;The guys from Alt.NET Hispano have put up the second part of my talk on MVC. You can view the video and download the code from &lt;a href="http://altnet-hispano.pbworks.com/Reuni%C3%B3n+VAN+Hispano+2009-05-09"&gt;here&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.imeta.co.uk/HHariri/aggbug/695.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Hadi Hariri </dc:creator>
            <guid>http://blogs.imeta.co.uk/HHariri/archive/2009/05/12/second-part-of-asp.net-mvc-alt.net-hispano-talk-avaiable.aspx</guid>
            <pubDate>Tue, 12 May 2009 17:11:45 GMT</pubDate>
            <comments>http://blogs.imeta.co.uk/HHariri/archive/2009/05/12/second-part-of-asp.net-mvc-alt.net-hispano-talk-avaiable.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.imeta.co.uk/HHariri/comments/commentRss/695.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.imeta.co.uk/HHariri/services/trackbacks/695.aspx</trackback:ping>
        </item>
        <item>
            <title>Second part of ASP.NET MVC on VAN Hispano: Same time, Same Place</title>
            <link>http://blogs.imeta.co.uk/HHariri/archive/2009/05/08/second-part-of-asp.net-mvc-on-van-hispano-same-time.aspx</link>
            <description>&lt;p&gt;I'll be doing the second part of the ASP.NET MVC talk on VAN Hispano (Virtual Alt.NET) on Saturday 8th of May, at 20:00 CET (Central European Time). The URL for the meeting is &lt;a href="http://snipr.com/virtualaltnet"&gt;http://snipr.com/virtualaltnet&lt;/a&gt;. This weeks pre-requisites is Spanish + knowledge of ASP.NET MVC.&lt;/p&gt;&lt;img src="http://blogs.imeta.co.uk/HHariri/aggbug/693.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Hadi Hariri </dc:creator>
            <guid>http://blogs.imeta.co.uk/HHariri/archive/2009/05/08/second-part-of-asp.net-mvc-on-van-hispano-same-time.aspx</guid>
            <pubDate>Fri, 08 May 2009 06:41:14 GMT</pubDate>
            <comments>http://blogs.imeta.co.uk/HHariri/archive/2009/05/08/second-part-of-asp.net-mvc-on-van-hispano-same-time.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.imeta.co.uk/HHariri/comments/commentRss/693.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.imeta.co.uk/HHariri/services/trackbacks/693.aspx</trackback:ping>
        </item>
        <item>
            <title>ASP.NET MVC &amp;quot;Models&amp;quot;: The lonesome folder!</title>
            <link>http://blogs.imeta.co.uk/HHariri/archive/2009/05/07/asp.net-mvc-quotmodelsquot-the-lonesome-folder.aspx</link>
            <description>&lt;p&gt;ASP.NET MVC comes with a Models folder but no Model. Although some see this as a shortcoming, I'm actually delighted that the framework does not bind me to a specific data technology or pattern. If I want to use Active Record I can use Castle's ActiveRecord. If I want to use a Repository Pattern, I can use NHibernate. If I want to throw something together for a quick prototype, I can use Linq 2 Sql. The advantage of not being tied to a specific data access pattern for me is a win situation.&lt;/p&gt;  &lt;p&gt;In many a demo, it's been indicated that the  "Models" folder contains your model, whatever that happens to be. It could be your Domain Model, your L2S entities, etc.  Now there are obvious reasons that whatever model you have, you wouldn't include it into your ASP.NET MVC application directly. You would probably reference it as an external assembly, and not directly place it in the Models folder.&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/ASP.NETMVCTheModelisViewModels_76CC/image_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="367" alt="image" src="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/ASP.NETMVCTheModelisViewModels_76CC/image_thumb.png" width="284" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;So this begs the question. Do we just remove the Models folder? Well before I answer that, let me dig into something else. &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Binding in ASP.NET MVC&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;We've seen many demos and tutorials where our model is directly passed in into our actions. We would have something along the lines of:&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/ASP.NETMVCTheModelisViewModels_76CC/image_6.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="291" alt="image" src="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/ASP.NETMVCTheModelisViewModels_76CC/image_thumb_2.png" width="484" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;ASP.NET MVC's binding is pretty powerful. It can reflect on the properties of your class (even if they contain complex types) and match these up to the properties that come through over the wire, via the request POST. As long as you name the properties the same, it works like a charm. One issue that this introduces, as outlined by &lt;a href="http://www.codethinked.com/post/2009/01/08/ASPNET-MVC-Think-Before-You-Bind.aspx"&gt;Justine in his post&lt;/a&gt;, as well as many others, is that the binding can come back to bite you. If you Customer entity has a field that you don't want the user to be able to update, you'll need to explicitly specify this by using attributes:&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/ASP.NETMVCTheModelisViewModels_76CC/image_8.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="82" alt="image" src="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/ASP.NETMVCTheModelisViewModels_76CC/image_thumb_3.png" width="495" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;However, as simple as it might seem, it's error prone and violates DRY. Alternatives to this approach include creating custom model binders or using interfaces to specify the properties that you want to be databound. But let's hold that thought for a moment. &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;A typical update scenario for a typical entity&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;The following screen has a sample form to fill in the details for a customer&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/ASP.NETMVCTheModelisViewModels_76CC/image_10.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="302" alt="image" src="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/ASP.NETMVCTheModelisViewModels_76CC/image_thumb_4.png" width="474" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;It's pretty standard. A bunch of fields and some dropdowns. But how is the dropdown values set? You could set them in the controller action just before displaying the view, using ViewData:&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/ASP.NETMVCTheModelisViewModels_76CC/image_12.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="94" alt="image" src="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/ASP.NETMVCTheModelisViewModels_76CC/image_thumb_5.png" width="636" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;Now I don't know about you, but for me, using ViewData is a smell. If we don't use ViewData to pass information about our model, why should we be using it to pass information that our model indirectly consumes? And of course, being a dictionary that it is, it's prone to errors. &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;One plus one makes habitants for Models folder&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;We have two problems to solve:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Binding to only those properties that we need &lt;/li&gt;    &lt;li&gt;Passing additional information to our views in a strongly-typed manner &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Well this just cries out for a new class to encapsulate this information, i.e. a view model. Instead of binding directly to entities, you can bind to a new class that exposes only the information that is allowed to be updated. You can also use this class to provide other information required for a particular view. In the case of Customer, we could end up with something along the lines of:&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/ASP.NETMVCTheModelisViewModels_76CC/image_18.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="313" alt="image" src="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/ASP.NETMVCTheModelisViewModels_76CC/image_thumb_8.png" width="753" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;In this case, we are using CustomerData as a DTO to hold the customer data (Name, Email, etc.) and the CustomerCreateViewModel as the View Model to hold other pertinent information for that particular view, for instance a list of countries. The action would now pass in this model as opposed to Customer:&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/ASP.NETMVCTheModelisViewModels_76CC/image_20.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="143" alt="image" src="http://blogs.imeta.co.uk/images/blogs_imeta_co_uk/HHariri/WindowsLiveWriter/ASP.NETMVCTheModelisViewModels_76CC/image_thumb_9.png" width="744" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;We now have a strongly-typed model to represent all the information we need for a particular view, and since it pertains to the current MVC application and specific Views, what better place to hold this than the Models folder.  Obviously based on your needs, you could provide a flattened version of this ViewModel but it does provide a cleaner approach to separate the actual DTO of your entity from the surrounding &lt;em&gt;auxiliary&lt;/em&gt; requirements for a view.&lt;/p&gt;  &lt;p&gt;Note: you need to make sure that you always provide a default parameter-less constructor for your view models since the framework requires this on binding. &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;By using strongly-typed views, you get the best of all worlds. You are able to make use of the binding provided by the MVC framework and it also provides a clean approach to providing specific data for views. And if that still doesn't cut it for you, think that you're making a home out of your Models folder!&lt;/p&gt;&lt;img src="http://blogs.imeta.co.uk/HHariri/aggbug/692.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Hadi Hariri </dc:creator>
            <guid>http://blogs.imeta.co.uk/HHariri/archive/2009/05/07/asp.net-mvc-quotmodelsquot-the-lonesome-folder.aspx</guid>
            <pubDate>Thu, 07 May 2009 08:18:14 GMT</pubDate>
            <comments>http://blogs.imeta.co.uk/HHariri/archive/2009/05/07/asp.net-mvc-quotmodelsquot-the-lonesome-folder.aspx#feedback</comments>
            <slash:comments>24</slash:comments>
            <wfw:commentRss>http://blogs.imeta.co.uk/HHariri/comments/commentRss/692.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.imeta.co.uk/HHariri/services/trackbacks/692.aspx</trackback:ping>
        </item>
    </channel>
</rss>