<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" 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:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Dan Miser - ASP.NET MVC</title>
    <link>http://www.distribucon.com/blog/</link>
    <description>Thoughts from Dan Miser</description>
    <language>en-us</language>
    <copyright>Dan Miser</copyright>
    <lastBuildDate>Wed, 24 Feb 2010 04:12:13 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>dmiser@distribucon.com</managingEditor>
    <webMaster>dmiser@distribucon.com</webMaster>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=2f555d4f-9a98-46e3-8aa4-0dbc6a20d135</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,2f555d4f-9a98-46e3-8aa4-0dbc6a20d135.aspx</pingback:target>
      <dc:creator>Dan Miser</dc:creator>
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,2f555d4f-9a98-46e3-8aa4-0dbc6a20d135.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=2f555d4f-9a98-46e3-8aa4-0dbc6a20d135</wfw:commentRss>
      <slash:comments>4</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">I use <a href="http://stackoverflow.com/questions/653514/asp-net-mvc-model-binding-an-ilist-parameter" target="_new">list
binding</a> in my ASP.NET MVC applications in several places. When it works, it is
truly magnificent. When it doesn't, it's just maddening. Here's a quick heads up for
those of you that use list binding in MVC. You would expect the following 2 lines
to render the same HTML, but they don't. To get list binding to work, you need the
HTML to read something like this (I'm just listing the attributes in question here): 
<p /><pre><code> &lt;input name="Results[0].Score" /&gt; </code></pre><p />
The old TextBox helper works fine, since you're assigning the name attribute:<br /><pre><code> Html.TextBox("Results["+id+"].Score", Model.Score) </code></pre><p />
This code, however: <pre><code> Html.TextBoxFor(r =&gt; r.Score, new { name = "Results["
+ id + "].Score" }) </code></pre><p />
produces the following output, which means the Score property won't get bound properly. <pre><code> &lt;input
name="Score" /&gt; </code></pre><p />
The problem is that in the TextBoxFor code, the name attribute is ignored. To be more
precise, the custom name is added, but the attribute is then replaced by the name
derived from the model. <img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=2f555d4f-9a98-46e3-8aa4-0dbc6a20d135" /></body>
      <title>ASP.NET MVC list binding differences between TextBox and TextBoxFor</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,2f555d4f-9a98-46e3-8aa4-0dbc6a20d135.aspx</guid>
      <link>http://www.distribucon.com/blog/ASPNETMVCListBindingDifferencesBetweenTextBoxAndTextBoxFor.aspx</link>
      <pubDate>Wed, 24 Feb 2010 04:12:13 GMT</pubDate>
      <description>I use &lt;a href="http://stackoverflow.com/questions/653514/asp-net-mvc-model-binding-an-ilist-parameter" target="_new"&gt;list
binding&lt;/a&gt; in my ASP.NET MVC applications in several places. When it works, it is
truly magnificent. When it doesn't, it's just maddening. Here's a quick heads up for
those of you that use list binding in MVC. You would expect the following 2 lines
to render the same HTML, but they don't. To get list binding to work, you need the
HTML to read something like this (I'm just listing the attributes in question here): 
&lt;p /&gt;
&lt;pre&gt;&lt;code&gt; &amp;lt;input name="Results[0].Score" /&amp;gt; &lt;/code&gt;&lt;/pre&gt;
&lt;p /&gt;
The old TextBox helper works fine, since you're assigning the name attribute:&lt;br /&gt;
&lt;pre&gt;&lt;code&gt; Html.TextBox("Results["+id+"].Score", Model.Score) &lt;/code&gt;&lt;/pre&gt;
&lt;p /&gt;
This code, however: &lt;pre&gt;&lt;code&gt; Html.TextBoxFor(r =&amp;gt; r.Score, new { name = "Results["
+ id + "].Score" }) &lt;/code&gt;&lt;/pre&gt;
&lt;p /&gt;
produces the following output, which means the Score property won't get bound properly. &lt;pre&gt;&lt;code&gt; &amp;lt;input
name="Score" /&amp;gt; &lt;/code&gt;&lt;/pre&gt;
&lt;p /&gt;
The problem is that in the TextBoxFor code, the name attribute is ignored. To be more
precise, the custom name is added, but the attribute is then replaced by the name
derived from the model. &lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=2f555d4f-9a98-46e3-8aa4-0dbc6a20d135" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,2f555d4f-9a98-46e3-8aa4-0dbc6a20d135.aspx</comments>
      <category>.NET</category>
      <category>ALT.NET</category>
      <category>ASP.NET MVC</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=e6c300f9-9863-43da-958f-b8bfa4807a9a</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,e6c300f9-9863-43da-958f-b8bfa4807a9a.aspx</pingback:target>
      <dc:creator>Dan Miser</dc:creator>
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,e6c300f9-9863-43da-958f-b8bfa4807a9a.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=e6c300f9-9863-43da-958f-b8bfa4807a9a</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">I just updated my ASP.NET MVC 1.0 application
to use <a href="http://go.microsoft.com/fwlink/?LinkID=157071" target="_blank">ASP.NET
MVC 2 RC</a>. It was a pretty painless process. Be sure to follow the Release Notes
on the download page, and many applications will be ready to go. Here are some extra
things that might help get you unstuck:<br /><ul><li>
If you're using the ASP.NET MVC Futures (Microsoft.Web.Mvc) assembly, be sure to download
the <a href="http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=37423" target="_blank">new
one that works with ASP.NET MVC 2</a>.</li><li>
If you're using the Telerik ASP.NET MVC components, be sure to download version BETA
2009.3.1218 or later.</li><li>
Way, way, way back in the ASP.NET MVC 1.0 beta days, they had a very nice mechanism
to update lists of items by tying UI fields to index numbers, so you could use primary
key identifiers to help keep track of what fields were modified where. In the 1.0
RC release, Microsoft <a href="http://forums.asp.net/p/1377775/2906357.aspx" target="_blank">changed
how it worked to do things sequentially instead</a>. I was using the IndexModelBinder
found in that thread with great success ever since then. However, Microsoft added
back in the index support to ASP.NET MVC 2 RC. This means that you will have to delete
the old IndexModelBinder since it won't compile anymore. Thankfully, I didn't have
to change a line of my code. Nice job of code compatibility!!</li></ul><img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=e6c300f9-9863-43da-958f-b8bfa4807a9a" /></body>
      <title>ASP.NET MVC 2 RC Changes</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,e6c300f9-9863-43da-958f-b8bfa4807a9a.aspx</guid>
      <link>http://www.distribucon.com/blog/ASPNETMVC2RCChanges.aspx</link>
      <pubDate>Tue, 19 Jan 2010 02:52:39 GMT</pubDate>
      <description>I just updated my ASP.NET MVC 1.0 application to use &lt;a href="http://go.microsoft.com/fwlink/?LinkID=157071" target="_blank"&gt;ASP.NET
MVC 2 RC&lt;/a&gt;. It was a pretty painless process. Be sure to follow the Release Notes
on the download page, and many applications will be ready to go. Here are some extra
things that might help get you unstuck:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;
If you're using the ASP.NET MVC Futures (Microsoft.Web.Mvc) assembly, be sure to download
the &lt;a href="http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=37423" target="_blank"&gt;new
one that works with ASP.NET MVC 2&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
If you're using the Telerik ASP.NET MVC components, be sure to download version BETA
2009.3.1218 or later.&lt;/li&gt;
&lt;li&gt;
Way, way, way back in the ASP.NET MVC 1.0 beta days, they had a very nice mechanism
to update lists of items by tying UI fields to index numbers, so you could use primary
key identifiers to help keep track of what fields were modified where. In the 1.0
RC release, Microsoft &lt;a href="http://forums.asp.net/p/1377775/2906357.aspx" target="_blank"&gt;changed
how it worked to do things sequentially instead&lt;/a&gt;. I was using the IndexModelBinder
found in that thread with great success ever since then. However, Microsoft added
back in the index support to ASP.NET MVC 2 RC. This means that you will have to delete
the old IndexModelBinder since it won't compile anymore. Thankfully, I didn't have
to change a line of my code. Nice job of code compatibility!!&lt;/li&gt;
&lt;/ul&gt;
&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=e6c300f9-9863-43da-958f-b8bfa4807a9a" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,e6c300f9-9863-43da-958f-b8bfa4807a9a.aspx</comments>
      <category>.NET</category>
      <category>ASP.NET MVC</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=7894225c-ffc2-429b-9829-a49998567094</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,7894225c-ffc2-429b-9829-a49998567094.aspx</pingback:target>
      <dc:creator>Dan Miser</dc:creator>
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,7894225c-ffc2-429b-9829-a49998567094.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=7894225c-ffc2-429b-9829-a49998567094</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">Telerik just released an extremely impressive <a href="http://demos.telerik.com/aspnet-mvc/" target="_blank">library
of components</a> (Grid, Menu, TabStrip, and MenuBar), written for MVC. They are truly
first-class, from the architecture, to the development experience, to the finished
screens that your user sees. They released them as open-source, and even better, these
controls are written from the ground up to support ASP.NET MVC. 
<p />
Be sure to check out this awesome write up on how to <a href="http://weblogs.asp.net/rashid/archive/2009/11/05/using-telerik-mvc-grid-in-crud-scenario.aspx" target="_blank">Use
the grid in a CRUD scenario</a>. Very nicely done. 
<p />
I'm not a fan of the whole "Edit/Delete" action column. I'd much rather just have
a link on the column to take me to the detail screen. Here's the way I solved that: <pre><code> &lt;%
Html.Telerik().Grid(Model) .Name("Grid") .PrefixUrlParameters(false) .Columns(columns
=&gt; { columns.Add(o =&gt; o.CollectionDate).Template(c =&gt; { %&gt; &lt;%= Html.ActionLink(c.CollectionDate.ToShortDateString(),
"View", new { Id = c.Id })%&gt; &lt;% }).Width(40); columns.Add(o =&gt; o.Location.Name).Width(40);
}) .Scrollable() .Sortable() .Pageable() .Filterable() .Render(); %&gt; </code></pre><img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=7894225c-ffc2-429b-9829-a49998567094" /></body>
      <title>Telerik Extensions for ASP.NET MVC</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,7894225c-ffc2-429b-9829-a49998567094.aspx</guid>
      <link>http://www.distribucon.com/blog/TelerikExtensionsForASPNETMVC.aspx</link>
      <pubDate>Sun, 08 Nov 2009 03:00:21 GMT</pubDate>
      <description>Telerik just released an extremely impressive &lt;a href="http://demos.telerik.com/aspnet-mvc/" target="_blank"&gt;library
of components&lt;/a&gt; (Grid, Menu, TabStrip, and MenuBar), written for MVC. They are truly
first-class, from the architecture, to the development experience, to the finished
screens that your user sees. They released them as open-source, and even better, these
controls are written from the ground up to support ASP.NET MVC. 
&lt;p /&gt;
Be sure to check out this awesome write up on how to &lt;a href="http://weblogs.asp.net/rashid/archive/2009/11/05/using-telerik-mvc-grid-in-crud-scenario.aspx" target="_blank"&gt;Use
the grid in a CRUD scenario&lt;/a&gt;. Very nicely done. 
&lt;p /&gt;
I'm not a fan of the whole "Edit/Delete" action column. I'd much rather just have
a link on the column to take me to the detail screen. Here's the way I solved that: &lt;pre&gt;&lt;code&gt; &amp;lt;%
Html.Telerik().Grid(Model) .Name("Grid") .PrefixUrlParameters(false) .Columns(columns
=&amp;gt; { columns.Add(o =&amp;gt; o.CollectionDate).Template(c =&amp;gt; { %&gt; &amp;lt;%= Html.ActionLink(c.CollectionDate.ToShortDateString(),
"View", new { Id = c.Id })%&amp;gt; &amp;lt;% }).Width(40); columns.Add(o =&amp;gt; o.Location.Name).Width(40);
}) .Scrollable() .Sortable() .Pageable() .Filterable() .Render(); %&amp;gt; &lt;/code&gt;&lt;/pre&gt;
&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=7894225c-ffc2-429b-9829-a49998567094" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,7894225c-ffc2-429b-9829-a49998567094.aspx</comments>
      <category>.NET</category>
      <category>ALT.NET</category>
      <category>ASP.NET MVC</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=5428f2ef-4962-44e0-ba14-1f18cb8bedc3</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,5428f2ef-4962-44e0-ba14-1f18cb8bedc3.aspx</pingback:target>
      <dc:creator>Dan Miser</dc:creator>
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,5428f2ef-4962-44e0-ba14-1f18cb8bedc3.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=5428f2ef-4962-44e0-ba14-1f18cb8bedc3</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">I've never been happier that I chose a
technology after today. I have a production web application built using ASP.NET MVC,
and it has been working with almost no issues for over a year now. As a matter of
fact, it is the cornerstone used to run our business. I've had the default blue skin
in use since day 1 (ya, ya, I know, I know. I've been so lazy, I haven't even switched
out to <a href="http://www.asp.net/MVC/Gallery/" target="_blank">pre-built templates</a>),
and we run the app on the iPhone. It works, but there's always pinching, zooming and
scrolling going on. I finally bit the bullet after thinking to myself "Why not create
a view tailored to the iPhone to enhance the experience?" one too many times. About
12 hours later, the entire application was done with an auto-detected, optimized look
and feel for the iPhone. I am now convinced that I've just been paid back with the
technical dividends for investing in ASP.NET MVC. :) 
<p />
To help the next guy out who walks down this path, here are all of the links that
I used during this process: 
<ul><li><a href="http://weblogs.asp.net/aaronlerch/archive/2008/06/08/rock-the-iphone-with-asp-net-mvc.aspx" target="_blank">Aaron
Lerch's seminal article</a> on using iUI</li><li><a href="http://code.google.com/p/iui/" target="_blank">iUI project home page</a> (Be
sure to use 0.31. It is lightning fast!)</li><li><a href="http://www.hanselman.com/blog/TheWeeklySourceCode28IPhoneWithASPNETMVCEdition.aspx" target="_blank">Scott
Hanselman's article</a> that introduced the auto-detect view engine</li><li><a href="http://www.k10design.net/articles/iui/" target="_blank">CW Zachary's article</a> that
gives some extensions to iUI (like tables, load/unload, and script/css execution)</li><li><a href="http://video.yahoo.com/watch/853528/3491272" target="_blank">Joe Hewitt's
introductory video</a>. Nice presentation, and the _replace nugget was worth the 15
minutes to watch it.</li></ul><img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=5428f2ef-4962-44e0-ba14-1f18cb8bedc3" /></body>
      <title>ASP.NET MVC on the iPhone</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,5428f2ef-4962-44e0-ba14-1f18cb8bedc3.aspx</guid>
      <link>http://www.distribucon.com/blog/ASPNETMVCOnTheIPhone.aspx</link>
      <pubDate>Fri, 06 Nov 2009 23:44:02 GMT</pubDate>
      <description>I've never been happier that I chose a technology after today. I have a production web application built using ASP.NET MVC, and it has been working with almost no issues for over a year now. As a matter of fact, it is the cornerstone used to run our business. I've had the default blue skin in use since day 1 (ya, ya, I know, I know. I've been so lazy, I haven't even switched out to &lt;a href="http://www.asp.net/MVC/Gallery/" target="_blank"&gt;pre-built
templates&lt;/a&gt;), and we run the app on the iPhone. It works, but there's always pinching,
zooming and scrolling going on. I finally bit the bullet after thinking to myself
"Why not create a view tailored to the iPhone to enhance the experience?" one too
many times. About 12 hours later, the entire application was done with an auto-detected,
optimized look and feel for the iPhone. I am now convinced that I've just been paid
back with the technical dividends for investing in ASP.NET MVC. :) 
&lt;p /&gt;
To help the next guy out who walks down this path, here are all of the links that
I used during this process: 
&lt;ul&gt;
&lt;li&gt;
&lt;a href="http://weblogs.asp.net/aaronlerch/archive/2008/06/08/rock-the-iphone-with-asp-net-mvc.aspx" target="_blank"&gt;Aaron
Lerch's seminal article&lt;/a&gt; on using iUI&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://code.google.com/p/iui/" target="_blank"&gt;iUI project home page&lt;/a&gt; (Be
sure to use 0.31. It is lightning fast!)&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://www.hanselman.com/blog/TheWeeklySourceCode28IPhoneWithASPNETMVCEdition.aspx" target="_blank"&gt;Scott
Hanselman's article&lt;/a&gt; that introduced the auto-detect view engine&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://www.k10design.net/articles/iui/" target="_blank"&gt;CW Zachary's article&lt;/a&gt; that
gives some extensions to iUI (like tables, load/unload, and script/css execution)&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://video.yahoo.com/watch/853528/3491272" target="_blank"&gt;Joe Hewitt's
introductory video&lt;/a&gt;. Nice presentation, and the _replace nugget was worth the 15
minutes to watch it.&lt;/li&gt;
&lt;/ul&gt;
&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=5428f2ef-4962-44e0-ba14-1f18cb8bedc3" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,5428f2ef-4962-44e0-ba14-1f18cb8bedc3.aspx</comments>
      <category>ASP.NET</category>
      <category>ASP.NET MVC</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=53f4be36-1d7b-43f7-8691-286b480ec9d2</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,53f4be36-1d7b-43f7-8691-286b480ec9d2.aspx</pingback:target>
      <dc:creator>Dan Miser</dc:creator>
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,53f4be36-1d7b-43f7-8691-286b480ec9d2.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=53f4be36-1d7b-43f7-8691-286b480ec9d2</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">Since my <a href="http://www.distribucon.com/blog/PopulatingDateRanges.aspx" target="_blank">last
post</a>, the date has changed from October 9th to October 12th. The reason this is
important is that the functions that needed to calculate the date based on the current
date are now coming through a different code path. Before, everything worked great.
As of October 10th, not so much. The fix is simple - the getDate function was missing
the parentheses to make it a method call. The fix is quite simple and is listed below: <pre><code> var
day = (now.getDate() &lt; 10) ? "0" + now.getDate() : now.getDate(); </code></pre><img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=53f4be36-1d7b-43f7-8691-286b480ec9d2" /></body>
      <title>Populating Date Ranges, part 2</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,53f4be36-1d7b-43f7-8691-286b480ec9d2.aspx</guid>
      <link>http://www.distribucon.com/blog/PopulatingDateRangesPart2.aspx</link>
      <pubDate>Tue, 13 Oct 2009 04:11:13 GMT</pubDate>
      <description>Since my &lt;a href="http://www.distribucon.com/blog/PopulatingDateRanges.aspx" target="_blank"&gt;last
post&lt;/a&gt;, the date has changed from October 9th to October 12th. The reason this is
important is that the functions that needed to calculate the date based on the current
date are now coming through a different code path. Before, everything worked great.
As of October 10th, not so much. The fix is simple - the getDate function was missing
the parentheses to make it a method call. The fix is quite simple and is listed below: &lt;pre&gt;&lt;code&gt; var
day = (now.getDate() &amp;lt; 10) ? "0" + now.getDate() : now.getDate(); &lt;/code&gt;&lt;/pre&gt;
&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=53f4be36-1d7b-43f7-8691-286b480ec9d2" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,53f4be36-1d7b-43f7-8691-286b480ec9d2.aspx</comments>
      <category>ASP.NET</category>
      <category>ASP.NET MVC</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=691a0e72-3786-4810-ad90-d064e6090fac</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,691a0e72-3786-4810-ad90-d064e6090fac.aspx</pingback:target>
      <dc:creator>Dan Miser</dc:creator>
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,691a0e72-3786-4810-ad90-d064e6090fac.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=691a0e72-3786-4810-ad90-d064e6090fac</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">I have several reports in my ASP.NET MVC
application that are date-oriented. I had start date and end date text boxes, and
things worked fine. What I really wanted was something that would allow those date
boxes to be populated with a variety of canned date ranges (e.g. Year to Date, Last
Month, etc.). I found just what I was looking for in a pure JavaScript implementation <a href="http://www.epalla.com/2009/06/using-javascript-to-calculate-dates/" target="_blank">here</a>. 
<p />
The one problem I found was that "Last Month" was being calculated incorrectly. Below
is the simple fix. Thanks to epalla for the original code. 
<p /><pre><code> // last month case "lastmo": // we need a new month variable for month-1,
also formatted correctly var lastmonth = ((month - 1) &lt; 10) ? "0" + (month - 1)
: (month - 1); startbox.value = lastmonth + "/01/" + year; // now grab the last day
of the month (30, 31? we don't know!) var moend = new Date(year, (month - 1), 0);
endbox.value = lastmonth + "/" + moend.getDate() + "/" + year; break; </code></pre><img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=691a0e72-3786-4810-ad90-d064e6090fac" /></body>
      <title>Populating Date Ranges</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,691a0e72-3786-4810-ad90-d064e6090fac.aspx</guid>
      <link>http://www.distribucon.com/blog/PopulatingDateRanges.aspx</link>
      <pubDate>Fri, 09 Oct 2009 01:44:07 GMT</pubDate>
      <description>I have several reports in my ASP.NET MVC application that are date-oriented. I had start date and end date text boxes, and things worked fine. What I really wanted was something that would allow those date boxes to be populated with a variety of canned date ranges (e.g. Year to Date, Last Month, etc.). I found just what I was looking for in a pure JavaScript implementation &lt;a href="http://www.epalla.com/2009/06/using-javascript-to-calculate-dates/" target="_blank"&gt;here&lt;/a&gt;. 
&lt;p /&gt;
The one problem I found was that "Last Month" was being calculated incorrectly. Below
is the simple fix. Thanks to epalla for the original code. 
&lt;p /&gt;
&lt;pre&gt;&lt;code&gt; // last month case "lastmo": // we need a new month variable for month-1,
also formatted correctly var lastmonth = ((month - 1) &amp;lt; 10) ? "0" + (month - 1)
: (month - 1); startbox.value = lastmonth + "/01/" + year; // now grab the last day
of the month (30, 31? we don't know!) var moend = new Date(year, (month - 1), 0);
endbox.value = lastmonth + "/" + moend.getDate() + "/" + year; break; &lt;/code&gt;&lt;/pre&gt;
&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=691a0e72-3786-4810-ad90-d064e6090fac" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,691a0e72-3786-4810-ad90-d064e6090fac.aspx</comments>
      <category>ASP.NET</category>
      <category>ASP.NET MVC</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=a0a5275a-0c32-409a-b8f2-7b8e02ba71d5</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,a0a5275a-0c32-409a-b8f2-7b8e02ba71d5.aspx</pingback:target>
      <dc:creator>Dan Miser</dc:creator>
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,a0a5275a-0c32-409a-b8f2-7b8e02ba71d5.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=a0a5275a-0c32-409a-b8f2-7b8e02ba71d5</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">Given a set up like this (where ExpenseSummaryData
returns some arbitrary HTML fragment) : <pre><code> &lt;%using (Ajax.BeginForm("ExpenseSummaryData",
new AjaxOptions { UpdateTargetId = "result" })) { %&gt; &lt;label for="startDate"&gt;Start
Date:&lt;/label&gt; &lt;%= Html.TextBox("startDate") %&gt; &lt;br /&gt; &lt;label
for="endDate"&gt;End Date:&lt;/label&gt; &lt;%= Html.TextBox("endDate")%&gt; &lt;br
/&gt; &lt;input type="submit"/&gt; &lt;br /&gt; &lt;span id="result"/&gt; &lt;% }
%&gt; </code></pre><p />
If that is all your page does, you will notice that you get taken to a new page when
pressing Submit. The data on the new page is the HTML fragment returned by the AJAX
call, but that's all it contains (e.g. no master page), and it's clearly not replacing
the result span. 
<p />
The reason for this is that I forgot to add the following lines to the &lt;head&gt;
section in the original page: <pre><code> &lt;script src='&lt;%=ResolveUrl("~/Content/js/MicrosoftAjax.debug.js")%&gt;'
type="text/javascript"&gt;&lt;/script&gt; &lt;script src='&lt;%=ResolveUrl("~/Content/js/MicrosoftMvcAjax.debug.js")%&gt;'
type="text/javascript"&gt;&lt;/script&gt; </code></pre><p />
After adding those declarations in, the content in the span tag is properly updated
and it looks like a real AJAX call.<img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=a0a5275a-0c32-409a-b8f2-7b8e02ba71d5" /></body>
      <title>Why AJAX posts go to a new page instead of updating UpdateTargetId</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,a0a5275a-0c32-409a-b8f2-7b8e02ba71d5.aspx</guid>
      <link>http://www.distribucon.com/blog/WhyAJAXPostsGoToANewPageInsteadOfUpdatingUpdateTargetId.aspx</link>
      <pubDate>Sun, 31 May 2009 16:38:24 GMT</pubDate>
      <description>Given a set up like this (where ExpenseSummaryData returns some arbitrary HTML fragment) :
&lt;pre&gt;&lt;code&gt; &amp;lt;%using
(Ajax.BeginForm("ExpenseSummaryData", new AjaxOptions { UpdateTargetId = "result"
})) { %&amp;gt; &amp;lt;label for="startDate"&amp;gt;Start Date:&amp;lt;/label&amp;gt; &amp;lt;%= Html.TextBox("startDate")
%&amp;gt; &amp;lt;br /&amp;gt; &amp;lt;label for="endDate"&amp;gt;End Date:&amp;lt;/label&amp;gt; &amp;lt;%= Html.TextBox("endDate")%&amp;gt;
&amp;lt;br /&amp;gt; &amp;lt;input type="submit"/&amp;gt; &amp;lt;br /&amp;gt; &amp;lt;span id="result"/&amp;gt; &amp;lt;%
} %&amp;gt; &lt;/code&gt;&lt;/pre&gt;
&lt;p /&gt;
If that is all your page does, you will notice that you get taken to a new page when
pressing Submit. The data on the new page is the HTML fragment returned by the AJAX
call, but that's all it contains (e.g. no master page), and it's clearly not replacing
the result span. 
&lt;p /&gt;
The reason for this is that I forgot to add the following lines to the &amp;lt;head&amp;gt;
section in the original page: &lt;pre&gt;&lt;code&gt; &amp;lt;script src='&amp;lt;%=ResolveUrl("~/Content/js/MicrosoftAjax.debug.js")%&amp;gt;'
type="text/javascript"&amp;gt;&amp;lt;/script&amp;gt; &amp;lt;script src='&amp;lt;%=ResolveUrl("~/Content/js/MicrosoftMvcAjax.debug.js")%&amp;gt;'
type="text/javascript"&amp;gt;&amp;lt;/script&amp;gt; &lt;/code&gt;&lt;/pre&gt;
&lt;p /&gt;
After adding those declarations in, the content in the span tag is properly updated
and it looks like a real AJAX call.&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=a0a5275a-0c32-409a-b8f2-7b8e02ba71d5" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,a0a5275a-0c32-409a-b8f2-7b8e02ba71d5.aspx</comments>
      <category>.NET</category>
      <category>ASP.NET MVC</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=ac208445-ed41-40cb-98ac-af77d227ef51</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,ac208445-ed41-40cb-98ac-af77d227ef51.aspx</pingback:target>
      <dc:creator>Dan Miser</dc:creator>
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,ac208445-ed41-40cb-98ac-af77d227ef51.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=ac208445-ed41-40cb-98ac-af77d227ef51</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I've been playing with ways to write a solid (and even <a href="http://www.hanselminutes.com/default.aspx?showID=163" target="_blank">SOLID</a> :))
architecture with ASP.NET MVC. I started with a plain LINQ to SQL approach, and then
migrated to <a href="http://www.mindscape.co.nz/products/LightSpeed/default.aspx" target="_blank">LightSpeed</a>,
and finally ended up checking out <a href="http://groups.google.com/group/sharp-architecture" target="_blank">S#arp</a> last
week. Here are my notes of pros/cons on each approach. Yes, I could (and most likely
will) address some concerns by writing code for it. This is more of a laundry list
of the state of things as I see them at this point in time.
</p>
        <h3>LINQ to SQL
</h3>
        <h4>Pros
</h4>
        <ul>
          <li>
Visual designer 
</li>
        </ul>
        <h4>Cons
</h4>
        <ul>
          <li>
MS is talking about <a href="http://blogs.msdn.com/adonet/archive/2008/10/29/update-on-linq-to-sql-and-linq-to-entities-roadmap.aspx" target="_blank">phasing
LINQ to SQL out</a> and forcing people towards Entity Framework. I'm pretty sick of
chasing MS's data-access strategies around every year. 
</li>
          <li>
LINQ to SQL mostly defaults you to a 1:1 mapping between your database and your model. 
</li>
          <li>
Support for modifications to the schema sucks, to be generous. 
</li>
          <li>
No UnitOfWork concept. Of course, as I prepared this blog entry, I found <a href="http://www.geekvue.com/2009/02/26/implementing-unitofwork-pattern-in-linq-to-sql-application/" target="_blank">this
article</a> published just today, so maybe that would address this point. 
</li>
        </ul>
        <h3>LightSpeed
</h3>
        <h4>Pros
</h4>
        <ul>
          <li>
Support is outstanding. 
</li>
          <li>
Nightly builds are available. 
</li>
          <li>
Visual designer. 
</li>
          <li>
Proven patterns bundled in their core libraries (UnitOfWork, Repository, Entity, etc.). 
</li>
          <li>
Picks up changes from the schema flawlessly. 
</li>
        </ul>
        <h4>Cons
</h4>
        <ul>
          <li>
Commercial and propietary. 
</li>
          <li>
Lacks quite a bit of LINQ support. For example, <a href="http://www.mindscape.co.nz/forums/Thread.aspx?PostID=3377" target="_blank">groupby
and join</a> are not supported. This meant that I use LINQ to SQL when I need these
features. Fortunately, that's all isolated to my report module, so it's not as horrible
as it could be. 
</li>
        </ul>
        <h3>S#arp
</h3>
        <h4>Pros
</h4>
        <ul>
          <li>
Open Source 
</li>
          <li>
Uses standard, widely adopted open source libraries: NHibernate, Windsor, etc. 
</li>
          <li>
Convention over Configuration 
</li>
          <li>
Scaffolding</li>
        </ul>
        <h4>Cons
</h4>
        <ul>
          <li>
I'm not digging the T4 templating mechanism. They conflict with VisualSVN and Developer
Express tools, and having to write a template for each and every entity is cumbersome. 
</li>
          <li>
No visual designer 
</li>
          <li>
No ability to import entities from an existing database. Yes, they like DDD, but in
almost every project I've been a part of, the database is the thing that already exists. 
</li>
          <li>
No UnitOfWork pattern (I might be able to fit code out there that does this in with
S#arp). The [Transaction] attribute approach feels a bit dirty. 
</li>
          <li>
The scaffolding is a bit too simple. It doesn't build up object graphs with links
(for display) or SelectLists (for editing). Yes, I can add that. It probably will
get that functionality at some point, too. But it doesn't do it right now.</li>
        </ul>
        <p>
For now, I think I'll be staying with LightSpeed, but I'll be watching S#arp very
carefully.
</p>
        <img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=ac208445-ed41-40cb-98ac-af77d227ef51" />
      </body>
      <title>ASP.NET MVC Architecture Round-up</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,ac208445-ed41-40cb-98ac-af77d227ef51.aspx</guid>
      <link>http://www.distribucon.com/blog/ASPNETMVCArchitectureRoundup.aspx</link>
      <pubDate>Thu, 26 Feb 2009 21:17:53 GMT</pubDate>
      <description>&lt;p&gt;
I've been playing with ways to write a solid (and even &lt;a href="http://www.hanselminutes.com/default.aspx?showID=163" target="_blank"&gt;SOLID&lt;/a&gt; :))
architecture with ASP.NET MVC. I started with a plain LINQ to SQL approach, and then
migrated to &lt;a href="http://www.mindscape.co.nz/products/LightSpeed/default.aspx" target="_blank"&gt;LightSpeed&lt;/a&gt;,
and finally ended up checking out &lt;a href="http://groups.google.com/group/sharp-architecture" target="_blank"&gt;S#arp&lt;/a&gt; last
week. Here are my notes of pros/cons on each approach. Yes, I could (and most likely
will) address some concerns by writing code for it. This is more of a laundry list
of the state of things as I see them at this point in time.
&lt;/p&gt;
&lt;h3&gt;LINQ to SQL
&lt;/h3&gt;
&lt;h4&gt;Pros
&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
Visual designer 
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;Cons
&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
MS is talking about &lt;a href="http://blogs.msdn.com/adonet/archive/2008/10/29/update-on-linq-to-sql-and-linq-to-entities-roadmap.aspx" target="_blank"&gt;phasing
LINQ to SQL out&lt;/a&gt; and forcing people towards Entity Framework. I'm pretty sick of
chasing MS's data-access strategies around every year. 
&lt;li&gt;
LINQ to SQL mostly defaults you to a 1:1 mapping between your database and your model. 
&lt;li&gt;
Support for modifications to the schema sucks, to be generous. 
&lt;li&gt;
No UnitOfWork concept. Of course, as I prepared this blog entry, I found &lt;a href="http://www.geekvue.com/2009/02/26/implementing-unitofwork-pattern-in-linq-to-sql-application/" target="_blank"&gt;this
article&lt;/a&gt; published just today, so maybe that would address this point. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;LightSpeed
&lt;/h3&gt;
&lt;h4&gt;Pros
&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
Support is outstanding. 
&lt;li&gt;
Nightly builds are available. 
&lt;li&gt;
Visual designer. 
&lt;li&gt;
Proven patterns bundled in their core libraries (UnitOfWork, Repository, Entity, etc.). 
&lt;li&gt;
Picks up changes from the schema flawlessly. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;Cons
&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
Commercial and propietary. 
&lt;li&gt;
Lacks quite a bit of LINQ support. For example, &lt;a href="http://www.mindscape.co.nz/forums/Thread.aspx?PostID=3377" target="_blank"&gt;groupby
and join&lt;/a&gt; are not supported. This meant that I use LINQ to SQL when I need these
features. Fortunately, that's all isolated to my report module, so it's not as horrible
as it could be. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;S#arp
&lt;/h3&gt;
&lt;h4&gt;Pros
&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
Open Source 
&lt;li&gt;
Uses standard, widely adopted open source libraries: NHibernate, Windsor, etc. 
&lt;li&gt;
Convention over Configuration 
&lt;li&gt;
Scaffolding&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;Cons
&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
I'm not digging the T4 templating mechanism. They conflict with VisualSVN and Developer
Express tools, and having to write a template for each and every entity is cumbersome. 
&lt;li&gt;
No visual designer 
&lt;li&gt;
No ability to import entities from an existing database. Yes, they like DDD, but in
almost every project I've been a part of, the database is the thing that already exists. 
&lt;li&gt;
No UnitOfWork pattern (I might be able to fit code out there that does this in with
S#arp). The [Transaction] attribute approach feels a bit dirty. 
&lt;li&gt;
The scaffolding is a bit too simple. It doesn't build up object graphs with links
(for display) or SelectLists (for editing). Yes, I can add that. It probably will
get that functionality at some point, too. But it doesn't do it right now.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
For now, I think I'll be staying with LightSpeed, but I'll be watching S#arp very
carefully.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=ac208445-ed41-40cb-98ac-af77d227ef51" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,ac208445-ed41-40cb-98ac-af77d227ef51.aspx</comments>
      <category>ASP.NET MVC</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=727ded4f-19b9-41c6-a7b9-2062f0fc570a</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,727ded4f-19b9-41c6-a7b9-2062f0fc570a.aspx</pingback:target>
      <dc:creator>Dan Miser</dc:creator>
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,727ded4f-19b9-41c6-a7b9-2062f0fc570a.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=727ded4f-19b9-41c6-a7b9-2062f0fc570a</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
At work, a debate broke out over MVC. In that debate, <a href="http://chriscpetersonblog.blogspot.com/" target="_blank">Chris
Peterson</a> commented that he hated the way things looked on the view pages, specifically
with code executing in the view context. By way of example, he talked about the need
for a for loop to display a collection, and how he didn't like that. <a href="http://www.zorched.net" target="_blank">Geoff
Lane</a> commented that Grails had support for this built-in.
</p>
        <p>
To overcome these objections, I wrote the following simple extension method:
</p>
        <div style="font-weight: bold; font-size: 10pt; background: black; color: white; font-family: consolas">
          <p style="margin: 0px">
            <span style="color: #cc7832">public</span>
            <span style="color: #cc7832">static</span>
            <span style="color: #cc7832">class</span>
            <span style="color: #ffc66d">RenderPartialCollectionExtension</span>
          </p>
          <p style="margin: 0px">
{
</p>
          <p style="margin: 0px">
    <span style="color: #cc7832">public</span><span style="color: #cc7832">static</span><span style="color: #cc7832">void</span> RenderPartialCollection&lt;T&gt;(<span style="color: #cc7832">this</span><span style="color: #ffc66d">HtmlHelper</span> htmlHelper, <span style="color: #cc7832">string</span> partialViewName, <span style="color: #6897bb">IList</span><span style="font-weight: normal">&lt;T&gt;
list)</span></p>
          <p style="margin: 0px">
    {
</p>
          <p style="margin: 0px">
        <span style="color: #cc7832">foreach</span> (T
item <span style="color: #cc7832">in</span> list)
</p>
          <p style="margin: 0px">
        {
</p>
          <p style="margin: 0px">
            htmlHelper.RenderPartial(partialViewName,
item);
</p>
          <p style="margin: 0px">
        }
</p>
          <p style="margin: 0px">
    }
</p>
          <p style="margin: 0px">
}
</p>
        </div>
        <p>
This means that instead of the old-style View page code, like this: 
</p>
        <div style="font-weight: bold; font-size: 10pt; background: black; color: white; font-family: consolas">
          <p style="margin: 0px">
            <span style="color: #6897bb">&lt;%</span>
          </p>
          <p style="margin: 0px">
   <span style="color: #cc7832">foreach</span> (<span style="color: #ffc66d">Foo</span> foo <span style="color: #cc7832">in</span> Model)
</p>
          <p style="margin: 0px">
   {
</p>
          <p style="margin: 0px">
       Html.RenderPartial(<span style="color: #a5c25c">"~/Partials/DisplayFoo.aspx"</span>,
foo);
</p>
          <p style="margin: 0px">
   }
</p>
          <p style="margin: 0px">
 <span style="color: #6897bb">%&gt;</span></p>
        </div>
        <p>
You can just write code like this: 
</p>
        <div style="font-weight: bold; font-size: 10pt; background: black; color: white; font-family: consolas">
          <p style="margin: 0px">
            <span style="color: #6897bb">&lt;%</span> Html.RenderPartialCollection&lt;<span style="color: #ffc66d">Foo</span><span style="font-weight: normal">&gt;(</span><span style="color: #a5c25c">"~/Partials/DisplayFoo.aspx"</span>,
Model); <span style="color: #6897bb">%&gt;</span></p>
        </div>
        <img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=727ded4f-19b9-41c6-a7b9-2062f0fc570a" />
      </body>
      <title>RenderPartial for a collection</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,727ded4f-19b9-41c6-a7b9-2062f0fc570a.aspx</guid>
      <link>http://www.distribucon.com/blog/RenderPartialForACollection.aspx</link>
      <pubDate>Fri, 30 Jan 2009 22:40:58 GMT</pubDate>
      <description>&lt;p&gt;
At work, a debate broke out over MVC. In that debate, &lt;a href="http://chriscpetersonblog.blogspot.com/" target="_blank"&gt;Chris
Peterson&lt;/a&gt; commented that he hated the way things looked on the view pages, specifically
with code executing in the view context. By way of example, he talked about the need
for a for loop to display a collection, and how he didn't like that. &lt;a href="http://www.zorched.net" target="_blank"&gt;Geoff
Lane&lt;/a&gt; commented that Grails had support for this built-in.
&lt;/p&gt;
&lt;p&gt;
To overcome these objections, I wrote the following simple extension method:
&lt;/p&gt;
&lt;div style="font-weight: bold; font-size: 10pt; background: black; color: white; font-family: consolas"&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #cc7832"&gt;public&lt;/span&gt; &lt;span style="color: #cc7832"&gt;static&lt;/span&gt; &lt;span style="color: #cc7832"&gt;class&lt;/span&gt; &lt;span style="color: #ffc66d"&gt;RenderPartialCollectionExtension&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #cc7832"&gt;public&lt;/span&gt; &lt;span style="color: #cc7832"&gt;static&lt;/span&gt; &lt;span style="color: #cc7832"&gt;void&lt;/span&gt; RenderPartialCollection&amp;lt;T&amp;gt;(&lt;span style="color: #cc7832"&gt;this&lt;/span&gt; &lt;span style="color: #ffc66d"&gt;HtmlHelper&lt;/span&gt; htmlHelper, &lt;span style="color: #cc7832"&gt;string&lt;/span&gt; partialViewName, &lt;span style="color: #6897bb"&gt;IList&lt;/span&gt;&lt;span style="font-weight: normal"&gt;&amp;lt;T&amp;gt;
list)&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #cc7832"&gt;foreach&lt;/span&gt; (T
item &lt;span style="color: #cc7832"&gt;in&lt;/span&gt; list)
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; htmlHelper.RenderPartial(partialViewName,
item);
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
This means that instead of the old-style View page code, like this: 
&lt;div style="font-weight: bold; font-size: 10pt; background: black; color: white; font-family: consolas"&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #6897bb"&gt;&amp;lt;%&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp; &lt;span style="color: #cc7832"&gt;foreach&lt;/span&gt; (&lt;span style="color: #ffc66d"&gt;Foo&lt;/span&gt; foo &lt;span style="color: #cc7832"&gt;in&lt;/span&gt; Model)
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Html.RenderPartial(&lt;span style="color: #a5c25c"&gt;"~/Partials/DisplayFoo.aspx"&lt;/span&gt;,
foo);
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&lt;span style="color: #6897bb"&gt;%&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
You can just write code like this: 
&lt;div style="font-weight: bold; font-size: 10pt; background: black; color: white; font-family: consolas"&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #6897bb"&gt;&amp;lt;%&lt;/span&gt; Html.RenderPartialCollection&amp;lt;&lt;span style="color: #ffc66d"&gt;Foo&lt;/span&gt;&lt;span style="font-weight: normal"&gt;&amp;gt;(&lt;/span&gt;&lt;span style="color: #a5c25c"&gt;"~/Partials/DisplayFoo.aspx"&lt;/span&gt;,
Model); &lt;span style="color: #6897bb"&gt;%&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=727ded4f-19b9-41c6-a7b9-2062f0fc570a" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,727ded4f-19b9-41c6-a7b9-2062f0fc570a.aspx</comments>
      <category>ASP.NET MVC</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=627e837f-cfbd-4194-b775-11d220a18b11</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,627e837f-cfbd-4194-b775-11d220a18b11.aspx</pingback:target>
      <dc:creator>Dan Miser</dc:creator>
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,627e837f-cfbd-4194-b775-11d220a18b11.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=627e837f-cfbd-4194-b775-11d220a18b11</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
It seems that ASP.NET MVC doesn't allow for strongly-typed partial views. If anyone
knows of a clean way to do it, I'd love to know!
</p>
        <p>
Take the following typical page declaration:
</p>
        <pre>
          <code>&lt;%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage&lt;Foo&gt;"
%&gt;</code>
        </pre>
        <p>
This declaration allows us to access the Foo.Bar property in the view page using the
following syntax: Model.Bar. This works really well, and we even get Intellisense
for Foo when accessing the Model property in the editor. In contrast, if we inherited
from the non-generic ViewPage, Model becomes a simple object type, which means type-casting
to get to our passed in model object. 
</p>
        <p>
However, using partial pages with a similar technique does not work. For example,
if we have a partial page (ViewPage or ViewUserControl) and call it like below, it
will not allow for strong typing of the page: 
</p>
        <pre>
          <code>Html.RenderPartial("DisplayFoo", foo)</code>
        </pre>
If we try to strongly type the page, it will result in an error like this at run-time: <pre><code>Parser
Error Message: Could not load type 'System.Web.Mvc.ViewPage<foo>
'.
</foo></code></pre><p>
One work-around is to create a code-behind file, and specify the strong typing there,
and then inherit the partial page from the code-behind. But I really don't like that.
RC1 made great strides to get rid of the code-behind mess, and I would prefer not
to reintroduce it just for this. 
</p><p><b>Update:</b> Thanks to bradleylandis in the ASP.NET MVC forum, he correctly figured
out that I had my partial page in a folder <i>other</i> than the Views folder. He
mentioned that you need to copy the web.config file from the Views folder to any folder
that you serve view pages out of. After doing that, I now have a strongly typed partial
page.<img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=627e837f-cfbd-4194-b775-11d220a18b11" /></p></body>
      <title>Strongly typed Partial Views</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,627e837f-cfbd-4194-b775-11d220a18b11.aspx</guid>
      <link>http://www.distribucon.com/blog/StronglyTypedPartialViews.aspx</link>
      <pubDate>Thu, 29 Jan 2009 19:22:09 GMT</pubDate>
      <description>&lt;p&gt;
It seems that ASP.NET MVC doesn't allow for strongly-typed partial views. If anyone
knows of a clean way to do it, I'd love to know!
&lt;/p&gt;
&lt;p&gt;
Take the following typical page declaration:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage&amp;lt;Foo&amp;gt;"
%&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
This declaration allows us to access the Foo.Bar property in the view page using the
following syntax: Model.Bar. This works really well, and we even get Intellisense
for Foo when accessing the Model property in the editor. In contrast, if we inherited
from the non-generic ViewPage, Model becomes a simple object type, which means type-casting
to get to our passed in model object. 
&lt;p&gt;
However, using partial pages with a similar technique does not work. For example,
if we have a partial page (ViewPage or ViewUserControl) and call it like below, it
will not allow for strong typing of the page: &lt;pre&gt;&lt;code&gt;Html.RenderPartial("DisplayFoo",
foo)&lt;/code&gt;&lt;/pre&gt;
If we try to strongly type the page, it will result in an error like this at run-time: &lt;pre&gt;&lt;code&gt;Parser
Error Message: Could not load type 'System.Web.Mvc.ViewPage&lt;foo&gt;
'.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
One work-around is to create a code-behind file, and specify the strong typing there,
and then inherit the partial page from the code-behind. But I really don't like that.
RC1 made great strides to get rid of the code-behind mess, and I would prefer not
to reintroduce it just for this. 
&lt;p&gt;
&lt;b&gt;Update:&lt;/b&gt; Thanks to bradleylandis in the ASP.NET MVC forum, he correctly figured
out that I had my partial page in a folder &lt;i&gt;other&lt;/i&gt; than the Views folder. He
mentioned that you need to copy the web.config file from the Views folder to any folder
that you serve view pages out of. After doing that, I now have a strongly typed partial
page.&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=627e837f-cfbd-4194-b775-11d220a18b11" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,627e837f-cfbd-4194-b775-11d220a18b11.aspx</comments>
      <category>ASP.NET MVC</category>
    </item>
  </channel>
</rss>