<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blog.irm.se/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Johan's Blog : ASP.NET MVC</title><link>http://blog.irm.se/blogs/johan/archive/tags/ASP.NET+MVC/default.aspx</link><description>Tags: ASP.NET MVC</description><dc:language>en</dc:language><generator>CommunityServer 2.1 (Build: 60809.935)</generator><item><title>Create Tag-Cloud from RSS Feed in ASP.NET MVC</title><link>http://blog.irm.se/blogs/johan/archive/2011/08/08/Create-Tag_2D00_Cloud-from-RSS-Feed-in-ASP.NET-MVC.aspx</link><pubDate>Mon, 08 Aug 2011 11:40:12 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48763</guid><dc:creator>johan</dc:creator><slash:comments>0</slash:comments><comments>http://blog.irm.se/blogs/johan/comments/48763.aspx</comments><wfw:commentRss>http://blog.irm.se/blogs/johan/commentrss.aspx?PostID=48763</wfw:commentRss><description>&lt;p&gt;Say you want to generate your own tag-cloud from a list of categories or tags you pull from an RSS-feed or similar. This is one way to do it. I’m using ASP.NET MVC for this sample which creates a simple tag-cloud in a Razor-view with HTML looking something like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/jdanforth/image_0507121F.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/jdanforth/image_thumb_3CD95642.png" width="436" height="239" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The controller-code to start out with looks like this, where you read in the RSS-feed into a &lt;strong&gt;SyndicationFeed&lt;/strong&gt; class, then pull out and flatten all the categories you have in that feed. Then group all those categories and count them to build up this simple view-model which is a Dictionary of category and percentage:&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e018791a-8bdf-4fb2-8e96-7476fe3d5b1d" class="wlWriterEditableSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background-color:#ffffff;overflow:auto;padding:2px 5px;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;HomeController&lt;/span&gt; : &lt;span style="color:#2b91af;"&gt;Controller&lt;/span&gt;&lt;br&gt; {&lt;br&gt;     &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;ActionResult&lt;/span&gt; Index()&lt;br&gt;     {&lt;br&gt;         &lt;span style="color:#008000;"&gt;//get feed&lt;/span&gt;&lt;br&gt;         &lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; feed = &lt;span style="color:#2b91af;"&gt;SyndicationFeed&lt;/span&gt;.Load(&lt;span style="color:#2b91af;"&gt;XmlReader&lt;/span&gt;.Create(&lt;span style="color:#a31515;"&gt;&amp;quot;http://blog.irm.se/blogs/MainFeed.aspx&amp;quot;&lt;/span&gt;));&lt;br&gt; &lt;br&gt;         &lt;span style="color:#008000;"&gt;//get flat list of all categories/tags in the feed&lt;/span&gt;&lt;br&gt;         &lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; categoriesList = feed.Items.SelectMany(item =&amp;gt; item.Categories).Select(category =&amp;gt; category.Name);&lt;br&gt; &lt;br&gt;         &lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; categoryGroups = categoriesList.GroupBy(category =&amp;gt; category);&lt;br&gt; &lt;br&gt;         &lt;span style="color:#0000ff;"&gt;decimal&lt;/span&gt; maxNrOfACategory = categoryGroups.Max(w =&amp;gt; w.Count());&lt;br&gt; &lt;br&gt;         &lt;span style="color:#008000;"&gt;//build a dictionary with category/percentage of all categories&lt;/span&gt;&lt;br&gt;         &lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; tagCloudDictionary = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt;, &lt;span style="color:#0000ff;"&gt;int&lt;/span&gt;&amp;gt;();&lt;br&gt;         &lt;span style="color:#0000ff;"&gt;foreach&lt;/span&gt; (&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; tag &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; categoryGroups)&lt;br&gt;         {&lt;br&gt;             &lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; percent = (tag.Count() / maxNrOfACategory) * 100;&lt;br&gt;             tagCloudDictionary.Add(tag.Key, (&lt;span style="color:#0000ff;"&gt;int&lt;/span&gt;)percent);&lt;br&gt;         }&lt;br&gt; &lt;br&gt;         &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; View(tagCloudDictionary);&lt;br&gt;     }&lt;br&gt; }&lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt; 
.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; }  &lt;p&gt;So now we got this view-model which is a &lt;strong&gt;Dictionary&amp;lt;string,int&amp;gt;&lt;/strong&gt; and contains category/percentage data like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/jdanforth/image_62CF0698.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/jdanforth/image_thumb_21C08734.png" width="251" height="328" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;So all we need to do is create some kind of cloud in HTML or similar in the view. One way of doing it is this, which creates the output shown at the top:&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5be2cc55-9b3d-4844-ac07-c8de04ab8194" class="wlWriterEditableSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background-color:#ffffff;overflow:auto;padding:2px 5px;"&gt;&lt;span style="background:#ffff00;"&gt;@model &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt;, &lt;span style="color:#0000ff;"&gt;int&lt;/span&gt;&amp;gt;&lt;br&gt; &lt;br&gt; &lt;span style="background:#ffff00;"&gt;@{&lt;/span&gt;&lt;br&gt;     ViewBag.Title = &lt;span style="color:#a31515;"&gt;&amp;quot;Index&amp;quot;&lt;/span&gt;;&lt;br&gt; }&lt;br&gt; &lt;br&gt; &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;h2&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;Tag cloud&lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;h2&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt; &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;div&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;style&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;width&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;: 400px; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;font-size&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;: 25px;&amp;quot;&amp;gt;&lt;/span&gt;&lt;br&gt;     &lt;span style="background:#ffff00;"&gt;@&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;foreach&lt;/span&gt; (&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; tag &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; Model)&lt;br&gt;     {&lt;br&gt;         &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;span&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;style&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;font-size: &lt;/span&gt;&lt;span style="background:#ffff00;"&gt;@(&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;tag.Value / 2 + 50&lt;/span&gt;&lt;span style="background:#ffff00;"&gt;)&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;%; &amp;quot;&amp;gt;&lt;/span&gt;&lt;br&gt;         &lt;span style="background:#ffff00;"&gt;@&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (tag.Value &amp;gt; 10)&lt;br&gt;         {&lt;br&gt;             &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;span&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;style&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;font-weight&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;: bold;&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="background:#ffff00;"&gt;@&lt;/span&gt;tag.Key &lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;span&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;         }&lt;br&gt;         &lt;span style="color:#0000ff;"&gt;else&lt;/span&gt;&lt;br&gt;         {&lt;br&gt;             &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;span&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background:#ffff00;"&gt;@&lt;/span&gt;tag.Key &lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;span&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;         }&lt;br&gt;         &lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;span&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;     }&lt;br&gt; &lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;div&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Obviously, to be able to click on a tag and so on you need to create a richer view-model, I just wanted to show how I grab and count the tags from the feed &lt;img style="border-bottom-style:none;border-left-style:none;border-top-style:none;border-right-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://weblogs.asp.net/blogs/jdanforth/wlEmoticon-smile_79ADD814.png" /&gt;&lt;/p&gt;
&lt;br /&gt;&lt;i&gt;Cross-posted from my blog at &lt;a href="http://weblogs.asp.net/jdanforth"&gt;http://weblogs.asp.net/jdanforth&lt;/a&gt;&lt;/i&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48763" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/johan/archive/tags/ASP.NET+MVC/default.aspx">ASP.NET MVC</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/c_2300_/default.aspx">c#</category></item><item><title>Compile ASP.NET MVC on TFS 2010 Build Server</title><link>http://blog.irm.se/blogs/johan/archive/2010/04/22/Compile-ASP.NET-MVC-on-TFS-2010-Build-Server.aspx</link><pubDate>Thu, 22 Apr 2010 17:18:42 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48680</guid><dc:creator>johan</dc:creator><slash:comments>0</slash:comments><comments>http://blog.irm.se/blogs/johan/comments/48680.aspx</comments><wfw:commentRss>http://blog.irm.se/blogs/johan/commentrss.aspx?PostID=48680</wfw:commentRss><description>&lt;p&gt;&lt;strong&gt;Note to self:&lt;/strong&gt; If you need to build ASP.NET MVC 2 applications on a fresh TFS 2010 Build Server without Visual Studio installed, copy the System.Web.Mvc.dll from your dev box to the build server and register it there.&lt;/p&gt;
&lt;br /&gt;&lt;i&gt;Cross-posted from my blog at &lt;a href="http://weblogs.asp.net/jdanforth"&gt;http://weblogs.asp.net/jdanforth&lt;/a&gt;&lt;/i&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48680" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/johan/archive/tags/ASP.NET+MVC/default.aspx">ASP.NET MVC</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/VS2010/default.aspx">VS2010</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/TFS/default.aspx">TFS</category></item><item><title>Fill a Select/Option from Json with jQuery</title><link>http://blog.irm.se/blogs/johan/archive/2009/04/03/Fill-a-Select_2F00_Option-from-Json-with-jQuery.aspx</link><pubDate>Fri, 03 Apr 2009 12:19:02 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48609</guid><dc:creator>johan</dc:creator><slash:comments>0</slash:comments><comments>http://blog.irm.se/blogs/johan/comments/48609.aspx</comments><wfw:commentRss>http://blog.irm.se/blogs/johan/commentrss.aspx?PostID=48609</wfw:commentRss><description>&lt;p&gt;&lt;img title="aspnet" border="0" alt="aspnet" align="right" src="http://weblogs.asp.net/blogs/jdanforth/aspnet_4860990D.jpg" width="380" height="76" /&gt;More jQuery and Json…&lt;/p&gt;  &lt;p&gt;To fill a listbox (select) with items from a Json call.&lt;/p&gt;  &lt;p&gt;I got this helper class to handle the options/items:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;SelectOption
&lt;/span&gt;{
    &lt;span style="color:blue;"&gt;public &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;String &lt;/span&gt;Value { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }
    &lt;span style="color:blue;"&gt;public &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;String &lt;/span&gt;Text { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }
}&lt;/pre&gt;

&lt;p&gt;A sample action/method in ASP.NET MVC that returns Json:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;JsonResult &lt;/span&gt;GetJson()
{
    &lt;span style="color:blue;"&gt;var &lt;/span&gt;list = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;SelectOption&lt;/span&gt;&amp;gt;
                   {
                       &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;SelectOption &lt;/span&gt;{ Value = &lt;span style="color:#a31515;"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;, Text = &lt;span style="color:#a31515;"&gt;&amp;quot;Aron&amp;quot; &lt;/span&gt;},
                       &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;SelectOption &lt;/span&gt;{ Value = &lt;span style="color:#a31515;"&gt;&amp;quot;2&amp;quot;&lt;/span&gt;, Text = &lt;span style="color:#a31515;"&gt;&amp;quot;Bob&amp;quot; &lt;/span&gt;},
                       &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;SelectOption &lt;/span&gt;{ Value = &lt;span style="color:#a31515;"&gt;&amp;quot;3&amp;quot;&lt;/span&gt;, Text = &lt;span style="color:#a31515;"&gt;&amp;quot;Charlie&amp;quot; &lt;/span&gt;},
                       &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;SelectOption &lt;/span&gt;{ Value = &lt;span style="color:#a31515;"&gt;&amp;quot;4&amp;quot;&lt;/span&gt;, Text = &lt;span style="color:#a31515;"&gt;&amp;quot;David&amp;quot; &lt;/span&gt;}
                   };
    &lt;span style="color:blue;"&gt;return &lt;/span&gt;Json(list);
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Some HTML and jQuery to fill the list at page load:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;
&lt;/span&gt;    &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;select &lt;/span&gt;&lt;span style="color:red;"&gt;id&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;MyList&amp;quot; /&amp;gt;
&lt;/span&gt;&lt;span style="color:blue;"&gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;script &lt;/span&gt;&lt;span style="color:red;"&gt;type&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;text/javascript&amp;quot;&amp;gt;

        &lt;/span&gt;$(document).ready(&lt;span style="color:blue;"&gt;function&lt;/span&gt;() {
            $.getJSON(&lt;span style="color:#a31515;"&gt;&amp;quot;/Json/GetJson&amp;quot;&lt;/span&gt;, &lt;span style="color:blue;"&gt;null&lt;/span&gt;, &lt;span style="color:blue;"&gt;function&lt;/span&gt;(data) {
                $(&lt;span style="color:#a31515;"&gt;&amp;quot;#MyList&amp;quot;&lt;/span&gt;).addItems(data);
            });
        });

        $.fn.addItems = &lt;span style="color:blue;"&gt;function&lt;/span&gt;(data) {
            &lt;span style="color:blue;"&gt;return this&lt;/span&gt;.each(&lt;span style="color:blue;"&gt;function&lt;/span&gt;() {
                &lt;span style="color:blue;"&gt;var &lt;/span&gt;list = &lt;span style="color:blue;"&gt;this&lt;/span&gt;;
                $.each(data, &lt;span style="color:blue;"&gt;function&lt;/span&gt;(index, itemData) {
                    &lt;span style="color:blue;"&gt;var &lt;/span&gt;option = &lt;span style="color:blue;"&gt;new &lt;/span&gt;Option(itemData.Text, itemData.Value);
                    list.add(option);
                });
            });
        };

        $(&lt;span style="color:#a31515;"&gt;&amp;quot;#MyList&amp;quot;&lt;/span&gt;).change(&lt;span style="color:blue;"&gt;function&lt;/span&gt;() {
            alert(&lt;span style="color:#a31515;"&gt;'you selected ' &lt;/span&gt;+ $(&lt;span style="color:blue;"&gt;this&lt;/span&gt;).val());
        });

    &lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;script&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;br /&gt;&lt;i&gt;Cross-posted from my blog at &lt;a href="http://weblogs.asp.net/jdanforth"&gt;http://weblogs.asp.net/jdanforth&lt;/a&gt;&lt;/i&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48609" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/johan/archive/tags/ASP.NET+MVC/default.aspx">ASP.NET MVC</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/Json/default.aspx">Json</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/jQuery/default.aspx">jQuery</category></item><item><title>Json, jQuery and ASP.NET MVC</title><link>http://blog.irm.se/blogs/johan/archive/2009/04/03/Json_2C00_-jQuery-and-ASP.NET-MVC.aspx</link><pubDate>Fri, 03 Apr 2009 12:01:20 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48608</guid><dc:creator>johan</dc:creator><slash:comments>0</slash:comments><comments>http://blog.irm.se/blogs/johan/comments/48608.aspx</comments><wfw:commentRss>http://blog.irm.se/blogs/johan/commentrss.aspx?PostID=48608</wfw:commentRss><description>&lt;p&gt;&lt;img title="aspnet" border="0" alt="aspnet" align="right" src="http://weblogs.asp.net/blogs/jdanforth/aspnet_4860990D.jpg" width="380" height="76" /&gt;I’m stacking a few things here related to Json, jQuery and ASP.NET MVC so that I can get to them later on.&lt;/p&gt;  &lt;p&gt;JQuery to grab some Json when a web page is loaded:&lt;/p&gt;  &lt;pre class="code"&gt;$(document).ready(&lt;span style="color:blue;"&gt;function&lt;/span&gt;() {
    $.getJSON(&lt;span style="color:#a31515;"&gt;&amp;quot;/MyController/MyJsonAction&amp;quot;&lt;/span&gt;, &lt;span style="color:blue;"&gt;null&lt;/span&gt;, &lt;span style="color:blue;"&gt;function&lt;/span&gt;(data) {&lt;br /&gt;        &lt;span style="color:green;"&gt;//do stuff with data here&lt;br /&gt;&lt;/span&gt;    });
});&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;The smallish code in the ASP.NET MVC controller:&lt;/p&gt;

&lt;div style="font-family:consolas;background:white;color:black;font-size:10pt;"&gt;
  &lt;div style="font-family:consolas;background:white;color:black;font-size:10pt;"&gt;
    &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;JsonResult&lt;/span&gt; GetJson()&lt;/p&gt;

    &lt;p style="margin:0px;"&gt;{&lt;/p&gt;

    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;return&lt;/span&gt; Json(GetList());&lt;/p&gt;

    &lt;p style="margin:0px;"&gt;}&lt;/p&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;It’s possible to use anonymous types with Json() as well, which is very useful but may be harder to unit test.&lt;/p&gt;
&lt;br /&gt;&lt;i&gt;Cross-posted from my blog at &lt;a href="http://weblogs.asp.net/jdanforth"&gt;http://weblogs.asp.net/jdanforth&lt;/a&gt;&lt;/i&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48608" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/johan/archive/tags/ASP.NET+MVC/default.aspx">ASP.NET MVC</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/Json/default.aspx">Json</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/jQuery/default.aspx">jQuery</category></item><item><title>Running ASP.NET MVC on Your Windows Home Server</title><link>http://blog.irm.se/blogs/johan/archive/2009/03/22/Running-ASP.NET-MVC-on-Your-Windows-Home-Server.aspx</link><pubDate>Sat, 21 Mar 2009 23:02:51 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48604</guid><dc:creator>johan</dc:creator><slash:comments>0</slash:comments><comments>http://blog.irm.se/blogs/johan/comments/48604.aspx</comments><wfw:commentRss>http://blog.irm.se/blogs/johan/commentrss.aspx?PostID=48604</wfw:commentRss><description>&lt;p&gt;&lt;img title="aspnet" border="0" alt="aspnet" align="right" src="http://weblogs.asp.net/blogs/jdanforth/aspnet_4860990D.jpg" width="380" height="76" /&gt;Right, so I ran the new Web Platform Installer 2.0 Beta on my WHS and it seems (so far) to have worked out quite well. I created a new MVC website with File-&amp;gt;New… and published it over to an MVC-directory on WHS (I have set that up earlier, with a file share and everything).&lt;/p&gt;  &lt;p&gt;Now, the version of IIS on Windows Home Server is IIS 6 (because WHS runs on Windows 2003 kind of), so ASP.NET MVC won’t work right out of the box. &lt;strong&gt;I was hoping that the Web Platform Installer would have taken care of that, but apparently not&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx" target="_blank"&gt;Phil Haack wrote a long, and very detailed blog post about how to set things up on IIS 6&lt;/a&gt;, so I’m following that, adding support for the .mvc extension, changing the routes in Global.asax and so on, and voila it works:&lt;/p&gt;  &lt;p&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="ASP.NET MVC in WHS" border="0" alt="ASP.NET MVC in WHS" src="http://weblogs.asp.net/blogs/jdanforth/image_147A51FB.png" width="644" height="410" /&gt; &lt;/p&gt;  &lt;p&gt;Now, I want to set up extension-less URL’s, which is prettier than having to have that .mvc extension in the URL. Phil cover this in his blog post as well, so I’m adding wildcard mappings, and here goes:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="Extension-less URLs" border="0" alt="Extension-less URLs" src="http://weblogs.asp.net/blogs/jdanforth/image_2A148A98.png" width="644" height="353" /&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;Isn’t that just great? I love my home server, maybe I can host my &lt;a href="http://writespace.codeplex.com/" target="_blank"&gt;Writespace&lt;/a&gt; Clickonce installer on my own server? Not too worried about the load on the server :)&lt;/p&gt;  &lt;p&gt;Watch this space for some sample stuff that will be located on my own server *big grin*&lt;/p&gt;
&lt;br /&gt;&lt;i&gt;Cross-posted from my blog at &lt;a href="http://weblogs.asp.net/jdanforth"&gt;http://weblogs.asp.net/jdanforth&lt;/a&gt;&lt;/i&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48604" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/johan/archive/tags/ASP.NET+MVC/default.aspx">ASP.NET MVC</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/Windows+Home+Server/default.aspx">Windows Home Server</category></item><item><title>Web Platform Installer 2.0 Beta on Windows Home Server</title><link>http://blog.irm.se/blogs/johan/archive/2009/03/21/Web-Platform-Installer-2.0-Beta-on-Windows-Home-Server.aspx</link><pubDate>Sat, 21 Mar 2009 22:15:05 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48603</guid><dc:creator>johan</dc:creator><slash:comments>0</slash:comments><comments>http://blog.irm.se/blogs/johan/comments/48603.aspx</comments><wfw:commentRss>http://blog.irm.se/blogs/johan/commentrss.aspx?PostID=48603</wfw:commentRss><description>&lt;p&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;margin-left:0px;border-top:0px;margin-right:0px;border-right:0px;" title="Web Platform Installer" border="0" alt="Web Platform Installer" align="right" src="http://weblogs.asp.net/blogs/jdanforth/image_450B6380.png" width="163" height="143" /&gt; I’ve been thinking of setting up ASP.NET MVC 1.0 on my WHS and also start learning some Silverlight stuff, so I took a risk, went to the &lt;a href="http://www.microsoft.com/web/downloads/platform.aspx" target="_blank"&gt;Microsoft Web Platform Installer&lt;/a&gt; page and clicked on the Beta 2.0 link. Downloaded the installer, marked ASP.NET MVC and the most necessary options and let it go. Should work, right?&lt;/p&gt;  &lt;p&gt;It had to reboot once to get Windows Installer 4.5 in, but it continued to chew on and after a few minutes:&lt;/p&gt;  &lt;p&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="Done!" border="0" alt="Done!" src="http://weblogs.asp.net/blogs/jdanforth/image_389D4057.png" width="458" height="314" /&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;Yay! Now I just have to get an MVC test application on there somehow… brb.&lt;/p&gt;
&lt;br /&gt;&lt;i&gt;Cross-posted from my blog at &lt;a href="http://weblogs.asp.net/jdanforth"&gt;http://weblogs.asp.net/jdanforth&lt;/a&gt;&lt;/i&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48603" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/johan/archive/tags/ASP.NET+MVC/default.aspx">ASP.NET MVC</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/Windows+Home+Server/default.aspx">Windows Home Server</category></item><item><title>ASP.NET MVC v1 Source Code Released</title><link>http://blog.irm.se/blogs/johan/archive/2009/03/19/ASP.NET-MVC-v1-Source-Code-Released.aspx</link><pubDate>Thu, 19 Mar 2009 09:47:09 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48601</guid><dc:creator>johan</dc:creator><slash:comments>0</slash:comments><comments>http://blog.irm.se/blogs/johan/comments/48601.aspx</comments><wfw:commentRss>http://blog.irm.se/blogs/johan/commentrss.aspx?PostID=48601</wfw:commentRss><description>&lt;p&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;margin-left:0px;border-left-width:0px;margin-right:0px;" title="aspnet" border="0" alt="aspnet" align="right" src="http://weblogs.asp.net/blogs/jdanforth/aspnet_4860990D.jpg" width="380" height="76" /&gt; Phil twitted that the &lt;a href="http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=24471" target="_blank"&gt;source code for ASP.NET MVC v1 is available on Codeplex&lt;/a&gt; now, so I guess it’ll be released as a proper installer on MSDN any time now.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;EDIT:&lt;/strong&gt; …and a few hours later &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=53289097-73ce-43bf-b6a6-35e00103cb4b&amp;amp;displaylang=en" target="_blank"&gt;it was on MSDN&lt;/a&gt; :)&lt;/p&gt;  &lt;p&gt;Congrats to &lt;a href="http://haacked.com/archive/2009/03/18/aspnet-mvc-rtw.aspx" target="_blank"&gt;Phil Haack&lt;/a&gt; and his merry men for doing such an awesome job!&lt;/p&gt;
&lt;br /&gt;&lt;i&gt;Cross-posted from my blog at &lt;a href="http://weblogs.asp.net/jdanforth"&gt;http://weblogs.asp.net/jdanforth&lt;/a&gt;&lt;/i&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48601" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/johan/archive/tags/ASP.NET+MVC/default.aspx">ASP.NET MVC</category></item><item><title>ASP.NET MVC Preview 5 Released</title><link>http://blog.irm.se/blogs/johan/archive/2008/08/30/ASP.NET-MVC-Preview-5-Released.aspx</link><pubDate>Sat, 30 Aug 2008 14:18:42 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48468</guid><dc:creator>johan</dc:creator><slash:comments>0</slash:comments><comments>http://blog.irm.se/blogs/johan/comments/48468.aspx</comments><wfw:commentRss>http://blog.irm.se/blogs/johan/commentrss.aspx?PostID=48468</wfw:commentRss><description>&lt;p&gt;Hey, I'm just helping to spread the word! A sampled a few links and quotes that has already been posted to blogosphere for your pleasure and knowledge. :)&lt;/p&gt;  &lt;p&gt;Download it here -&amp;gt; &lt;a href="http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=16775"&gt;http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=16775&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://haacked.com/archive/2008/08/29/asp.net-mvc-codeplex-preview-5-released.aspx" target="_blank"&gt;Phil Haack said&lt;/a&gt;:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;We didn&amp;#8217;t originally plan to have another preview. However, we implemented a few significant chunks of functionality and were dying to get feedback so that we could incorporate it into the product before Beta. It helps that with five or so of these interim releases, we&amp;#8217;ve become pretty efficient producing these releases.&lt;/p&gt;    &lt;p&gt;We plan to have our next release be our official &lt;a href="http://haacked.com/archive/2008/08/15/understanding-beta.aspx"&gt;Beta&lt;/a&gt;, which means we&amp;#8217;ll have a lot more test passes to produce and run before we release the next one.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Some preview 5 related blog posts:&lt;/p&gt;  &lt;p&gt;Brad Wilson wrote about &lt;a href="http://bradwilson.typepad.com/blog/2008/08/partial-renderi.html" target="_blank"&gt;changes to partial rendering and view engine in preview 5&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Maarten Balliauw wrote about &lt;a href="http://blog.maartenballiauw.be/post/2008/08/29/Form-validation-with-ASPNET-MVC-preview-5.aspx" target="_blank"&gt;easier form validation with preview 5&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Nick Berardi has a &lt;a href="http://www.coderjournal.com/2008/08/aspnet-mvc-preview-release-5/" target="_blank"&gt;list of news and changes&lt;/a&gt; and also a few issues he's found and submitted bug reports for:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://www.codeplex.com/aspnet/WorkItem/View.aspx?WorkItemId=2201"&gt;AcceptVerbAttribute Not Following HTTP Standards&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeplex.com/aspnet/WorkItem/View.aspx?WorkItemId=2202"&gt;ActionMethod Missing From ActionExecutingContext&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Derik Whittaker had a &lt;a href="http://devlicio.us/blogs/derik_whittaker/archive/2008/08/29/asp-net-mvc-drop-5-has-been-released.aspx" target="_blank"&gt;few comments regarding sealed classes in preview 5&lt;/a&gt;:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;It looks like that they removed the sealed keyword from many of the Attributes such as HandleErrorAttribute, AuthorizeAttribute and various other existing Attributes.&amp;#160; &lt;/p&gt;    &lt;p&gt;However, looks like many of the other attributes (some new, some not) such as AcceptVerbsAttribute, ModelBinderAttribute and NonActionAttribute are still marked as sealed.&amp;#160; Guys, please unseal all your stuff.&amp;#160; If you have a very, very, very valid reason then fine seal them.&amp;#160; But if not, let developers loose and unseal them.&lt;/p&gt;&lt;/blockquote&gt;
&lt;br /&gt;&lt;i&gt;Cross-posted from my blog at &lt;a href="http://weblogs.asp.net/jdanforth"&gt;http://weblogs.asp.net/jdanforth&lt;/a&gt;&lt;/i&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48468" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/johan/archive/tags/.NET+3.5/default.aspx">.NET 3.5</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/ASP.NET+MVC/default.aspx">ASP.NET MVC</category></item><item><title>Auto Postback with Javascript in ASP.NET MVC</title><link>http://blog.irm.se/blogs/johan/archive/2008/08/28/Auto-Postback-with-Javascript-in-ASP.NET-MVC.aspx</link><pubDate>Thu, 28 Aug 2008 12:20:53 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48467</guid><dc:creator>johan</dc:creator><slash:comments>0</slash:comments><comments>http://blog.irm.se/blogs/johan/comments/48467.aspx</comments><wfw:commentRss>http://blog.irm.se/blogs/johan/commentrss.aspx?PostID=48467</wfw:commentRss><description>&lt;p&gt;I've looked this up twice now so I'm posting it to my blog for future reference and as a quick-tip for others. Say you got a web page with a dropdown/select listbox and you want to reload/auto postback the page when the selection changes.&lt;/p&gt;  &lt;p&gt;&lt;img style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px;" height="94" alt="image" src="http://weblogs.asp.net/blogs/jdanforth/WindowsLiveWriter/AutoPostbackwithJavascriptinASP.NETMVC_C410/image_3.png" width="207" border="0" /&gt; &lt;/p&gt;  &lt;p&gt;One way to do this without involving a Javascript or Ajax library like jQuery (which probably is a good idea anyway :) is to use the &amp;quot;htmlAttributes&amp;quot; parameter of the Html.DropDownList() helper method and add a &amp;quot;onchange&amp;quot; attribute through an anonymous type. Something like this:&lt;/p&gt;  &lt;pre class="code"&gt;    Select a name: &lt;span&gt;&amp;lt;%&lt;span&gt;&lt;/span&gt;=&lt;/span&gt;Html.DropDownList(&lt;span&gt;&amp;quot;Name&amp;quot;&lt;/span&gt;, ViewData.Model, &lt;br /&gt;&lt;span&gt;new&lt;/span&gt; { onchange = &lt;span&gt;&amp;quot;doSomeJavascript()&amp;quot;&lt;/span&gt; })&lt;span&gt;%&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;To submit a form, for example:&lt;/p&gt;

&lt;pre class="code"&gt;    &lt;span&gt;&amp;lt;%&lt;/span&gt; &lt;span&gt;using&lt;/span&gt; (Html.Form&amp;lt;&lt;span&gt;HomeController&lt;/span&gt;&amp;gt;(p =&amp;gt; p.DropDown(), &lt;br /&gt;        &lt;span&gt;FormMethod&lt;/span&gt;.Post, &lt;span&gt;new&lt;/span&gt; { id = &lt;span&gt;&amp;quot;myform&amp;quot;&lt;/span&gt; }))
       {&lt;span&gt;%&amp;gt;
&lt;/span&gt;    Select a name: &lt;span&gt;&amp;lt;%&lt;span&gt;&lt;/span&gt;=&lt;/span&gt;Html.DropDownList(&lt;span&gt;&amp;quot;Name&amp;quot;&lt;/span&gt;, ViewData.Model, &lt;br /&gt;        &lt;span&gt;new&lt;/span&gt; { onchange = &lt;span&gt;&amp;quot;document.getElementById('myform').submit()&amp;quot;&lt;/span&gt; })&lt;span&gt;%&amp;gt;
&lt;/span&gt;    &lt;span&gt;&amp;lt;%&lt;/span&gt;  } &lt;span&gt;%&amp;gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;The minimal DropDown() method of the HomeController class to support this sample looks like this:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span&gt;public&lt;/span&gt; &lt;span&gt;object&lt;/span&gt; DropDown()
{
    &lt;span&gt;var&lt;/span&gt; list = &lt;span&gt;new&lt;/span&gt; &lt;span&gt;List&lt;/span&gt;&amp;lt;&lt;span&gt;string&lt;/span&gt;&amp;gt; { &lt;span&gt;&amp;quot;Adam&amp;quot;&lt;/span&gt;, &lt;span&gt;&amp;quot;Bob&amp;quot;&lt;/span&gt;, &lt;span&gt;&amp;quot;Charlie&amp;quot;&lt;/span&gt; };
    &lt;span&gt;return&lt;/span&gt; View(&lt;span&gt;new&lt;/span&gt; &lt;span&gt;SelectList&lt;/span&gt;(list, Request[&lt;span&gt;&amp;quot;Name&amp;quot;&lt;/span&gt;] ?? list.First()));
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;As you can see, the htmlAttributes parameter is available on many of the Html-helper methods and I'm using ot to add a name attribute to the HTML form as well.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;End Note About Basic Knowledge of Javascript and Html&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Heh, ASP.NET MVC sure forces you to dust off that old, basic knowledge of HTML and Javascript that I think every web developer should have but the ASP.NET programming model has made us forgot... One could argue that it's niggy gritty stuff that we shouldn't have to worry about, but for me it feels good to know I'm in full control of the generated HTML and I'm not sending one byte more on the wire than what's needed. Yes, it's possible to have the same control with standard ASP.NET applications and controls, but I've seen experienced developers make mistakes around this more than once. ViewState anyone? :D&lt;/p&gt;
&lt;br /&gt;&lt;i&gt;Cross-posted from my blog at &lt;a href="http://weblogs.asp.net/jdanforth"&gt;http://weblogs.asp.net/jdanforth&lt;/a&gt;&lt;/i&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48467" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/johan/archive/tags/.NET+3.5/default.aspx">.NET 3.5</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/ASP.NET+MVC/default.aspx">ASP.NET MVC</category></item><item><title>IronRuby with ASP.NET MVC</title><link>http://blog.irm.se/blogs/johan/archive/2008/07/21/IronRuby-with-ASP.NET-MVC.aspx</link><pubDate>Mon, 21 Jul 2008 15:59:56 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48440</guid><dc:creator>johan</dc:creator><slash:comments>0</slash:comments><comments>http://blog.irm.se/blogs/johan/comments/48440.aspx</comments><wfw:commentRss>http://blog.irm.se/blogs/johan/commentrss.aspx?PostID=48440</wfw:commentRss><description>&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/jdanforth/WindowsLiveWriter/IronRubywithASP.NETMVC_FD06/MVCIronRuby_2.png"&gt;&lt;img style="border-right:0px;border-top:0px;margin:5px;border-left:0px;border-bottom:0px;" height="185" alt="MVCIronRuby" src="http://weblogs.asp.net/blogs/jdanforth/WindowsLiveWriter/IronRubywithASP.NETMVC_FD06/MVCIronRuby_thumb.png" width="240" align="right" border="0" /&gt;&lt;/a&gt; Now that ASP.NET MVC preview 4 is out, &lt;a href="http://haacked.com/archive/2008/07/20/ironruby-aspnetmvc-prototype.aspx" target="_blank"&gt;Phil Haack did as promised and made available a working prototype of IronRuby + ASP.NET MVC integration&lt;/a&gt;. He wrote:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Now that Preview 4 is out, I revisited the prototype and got it working again. I use the term &lt;em&gt;working&lt;/em&gt; loosely here. Yeah, it works, but it is really rough around the edges.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;To be able to use Ruby with ASP.NET MVC there has to be some c# glue/bridge code, especially in global.asax, which loads the routing tables (via extensions) and points at a specially made Ruby Controller Factory:&lt;/p&gt;  &lt;p&gt;protected void Application_Start(object sender, EventArgs e)   &lt;br /&gt;{    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; RouteTable.Routes.LoadFromRuby();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; ControllerBuilder.Current.SetControllerFactory(new RubyControllerFactory());    &lt;br /&gt;} &lt;/p&gt;  &lt;p&gt;That glue code is placed in a c# library called IronRubyMvcLibrary, which also contains support for .rhtml view pages. The objects you need to use from within the view page is accessible through Ruby global variables - $model, $response, $html and so on. &lt;/p&gt;  &lt;p&gt;As &lt;a href="http://www.iunknown.com/2008/06/ironruby-and-aspnet-mvc.html" target="_blank"&gt;John&lt;/a&gt; and &lt;a href="http://haacked.com/archive/2008/07/20/ironruby-aspnetmvc-prototype.aspx" target="_blank"&gt;Phil&lt;/a&gt; points out, this is a prototype and a test to try out a few things with IronRuby and MVC, and I think it's cool. Much will change over time, like how they use instance variables on the controller to pass data to the view.&lt;/p&gt;  &lt;p&gt;This is a step towards something which may become quite popular in the Ruby community, and perhaps to Rails people who has to, or wants to, write web apps on the .NET platform in the future. For those that hasn't been looking at IronRuby yet and want to have some fun with this - note that you don't have any intellisense or anything lika that in Visual Studio yet. &lt;/p&gt;
&lt;br /&gt;&lt;i&gt;Cross-posted from my blog at &lt;a href="http://weblogs.asp.net/jdanforth"&gt;http://weblogs.asp.net/jdanforth&lt;/a&gt;&lt;/i&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48440" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/johan/archive/tags/ASP.NET+MVC/default.aspx">ASP.NET MVC</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/Ruby/default.aspx">Ruby</category></item><item><title>Fetching User Details from OpenId via Attribute Exchange</title><link>http://blog.irm.se/blogs/johan/archive/2008/07/11/Fetching-User-Details-from-OpenId-via-Attribute-Exchange.aspx</link><pubDate>Fri, 11 Jul 2008 14:09:41 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48438</guid><dc:creator>johan</dc:creator><slash:comments>0</slash:comments><comments>http://blog.irm.se/blogs/johan/comments/48438.aspx</comments><wfw:commentRss>http://blog.irm.se/blogs/johan/commentrss.aspx?PostID=48438</wfw:commentRss><description>&lt;p&gt;&lt;img style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px;" height="178" alt="CropperCapture[4]" src="http://weblogs.asp.net/blogs/jdanforth/WindowsLiveWriter/FetchingUserDetailsfromOpenIdviaAttribut_E340/CropperCapture%5B4%5D_1.png" width="240" align="right" border="0" /&gt;Rob Conery did &lt;a href="http://blog.wekeroad.com/mvc-storefront/mvcstore-part-16/" target="_blank"&gt;another excellent episode of his MVC Storefront series&lt;/a&gt; the other day where he ripped out his user membership code and replaced it with OpenId.&lt;/p&gt;  &lt;p&gt;Implementing the whole OpenId protocol yourself isn't necessary as there are some great libraries for you out there which makes it really, really simple to use and integrate with both WebFoms and A SP.NET MVC. Rob uses the &lt;a href="http://code.google.com/p/dotnetopenid/" target="_blank"&gt;DotNetOpenId library&lt;/a&gt; to authenticate the user but didn't show how to fetch user details like the user full name.&lt;/p&gt;  &lt;p&gt;Well, this is possible using Attribute Exchange which is a way of transferring information about the user between the OpenID provider and relying party. The DotNetOpenId library supports this too, and it just requires a small change to the DotNetOpenId code samples I've seen out there.&lt;/p&gt;  &lt;p&gt;First, most people redirect to the provider like this:&lt;/p&gt;  &lt;pre class="code"&gt;openid.CreateRequest(id).RedirectToProvider();&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;But instead, create the request manually and add extension requests to fetch user information (like the name for example) to it before redirecting:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span&gt;var&lt;/span&gt; openidRequest = openid.CreateRequest(id);
&lt;span&gt;var&lt;/span&gt; fetch = &lt;span&gt;new&lt;/span&gt; &lt;span&gt;FetchRequest&lt;/span&gt;();
fetch.AddAttribute(&lt;span&gt;new&lt;/span&gt; &lt;span&gt;AttributeRequest&lt;/span&gt;(&lt;span&gt;&amp;quot;http://schema.openid.net/namePerson&amp;quot;&lt;/span&gt;));
openidRequest.AddExtension(fetch);

openidRequest.RedirectToProvider();&lt;/pre&gt;

&lt;p&gt;Just keep on adding the attributes you're interested in, like email, website etc. Remeber to inform your user about you wanting to fetch the extra information before doing the authentication. &lt;/p&gt;

&lt;p&gt;After a successful OpenId authentication the provider redirects back to your site and you normally authenticate and redirect like this:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span&gt;switch&lt;/span&gt; (openid.Response.Status)
{
    &lt;span&gt;case&lt;/span&gt; &lt;span&gt;AuthenticationStatus&lt;/span&gt;.Authenticated:
        &lt;span&gt;FormsAuthentication&lt;/span&gt;.RedirectFromLoginPage(openid.Response.ClaimedIdentifier, &lt;span&gt;false&lt;/span&gt;);&lt;br /&gt;        &lt;span&gt;//...snip...&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Now, before the redirect statement, you have the chance to fetch out the attributes you asked for from the OpenId response, like this for example:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span&gt;switch&lt;/span&gt; (openid.Response.Status)
{
    &lt;span&gt;case&lt;/span&gt; &lt;span&gt;AuthenticationStatus&lt;/span&gt;.Authenticated:
        &lt;span&gt;var&lt;/span&gt; fetch = openid.Response.GetExtension&amp;lt;&lt;span&gt;FetchResponse&lt;/span&gt;&amp;gt;();
        &lt;span&gt;if&lt;/span&gt; (fetch != &lt;span&gt;null&lt;/span&gt;)
        {
            &lt;span&gt;//assuming we got data back from the provider - add sanity check to this :)
&lt;/span&gt;            &lt;span&gt;var&lt;/span&gt; name = fetch.GetAttribute(&lt;span&gt;&amp;quot;http://schema.openid.net/namePerson&amp;quot;&lt;/span&gt;).Values[0];
            &lt;span&gt;//...store name in session or something...&lt;br /&gt;&lt;/span&gt;        } &lt;br /&gt;        &lt;span&gt;FormsAuthentication&lt;/span&gt;.RedirectFromLoginPage(openid.Response.ClaimedIdentifier, &lt;span&gt;false&lt;/span&gt;);
        &lt;span&gt;//...snip...&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Note that DotNetOpenId library offers a few &amp;quot;well known&amp;quot; attributes as enums which all uses the &amp;quot;axschema.org&amp;quot; schema, but they do not work with the myOpenId provider. That's why I'm using the &amp;quot;schema.openid.net&amp;quot; schema instead.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://raku.to/"&gt;Rakuto Furutani&lt;/a&gt; blogged about &lt;a href="http://rakuto.blogspot.com/2008/03/ruby-fetch-some-attributes-from.html" target="_blank"&gt;the attribute schema problems&lt;/a&gt; in a Ruby on Rails post:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;myOpenID supports only some attributes that can be exchange with OpenID Attribute Exchange, but you should care about Type URI, because myOpenID doesn't support Type URI described on &amp;quot;http://www.axschema.org/types/&amp;quot;. &lt;strong&gt;You should specify Type URI with &amp;quot;http://schema.openid.net/&amp;quot; instead.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It could be I'm using an older version of the DotNetOpenId library and it's been changed in newed releases. I have to check this out.&lt;/p&gt;

&lt;p&gt;Also, &lt;a href="http://blog.nerdbank.net/" target="_blank"&gt;Andrew Arnott&lt;/a&gt; has written a longer post on &lt;a href="http://blog.nerdbank.net/2008/07/how-to-use-dotnetopenid-attribute.html" target="_blank"&gt;how to use DotNetOpenId's Attribute Extensions extension&lt;/a&gt; which you should read if you want some more in-depth sample code (he's using ASP.NET WebForms). &lt;/p&gt;
&lt;br /&gt;&lt;i&gt;Cross-posted from my blog at &lt;a href="http://weblogs.asp.net/jdanforth"&gt;http://weblogs.asp.net/jdanforth&lt;/a&gt;&lt;/i&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48438" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/johan/archive/tags/ASP.NET+MVC/default.aspx">ASP.NET MVC</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/OpenID/default.aspx">OpenID</category></item><item><title>ASP.NET MVC Resources</title><link>http://blog.irm.se/blogs/johan/archive/2008/06/05/ASP.NET-MVC-Resources.aspx</link><pubDate>Thu, 05 Jun 2008 10:48:12 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48431</guid><dc:creator>johan</dc:creator><slash:comments>0</slash:comments><comments>http://blog.irm.se/blogs/johan/comments/48431.aspx</comments><wfw:commentRss>http://blog.irm.se/blogs/johan/commentrss.aspx?PostID=48431</wfw:commentRss><description>&lt;p&gt;&lt;a href="http://weblogs.asp.net/craigshoemaker/default.aspx" target="_blank"&gt;Craig Shoemaker&lt;/a&gt;, the host of &lt;a href="http://polymorphicpodcast.com/" target="_blank"&gt;Polymorphic Podcast&lt;/a&gt; (a .NET podcast which is getting better and better all the time), published a &lt;a href="http://weblogs.asp.net/craigshoemaker/archive/2008/04/24/47-asp-net-mvc-resources-to-rock-your-development.aspx" target="_blank"&gt;great set of resources for ASP.NET MVC&lt;/a&gt; which will keep you occupied for hours.&lt;/p&gt;  &lt;p&gt;Also listen to his shows on MVC. He's got interviews with both Scott Hanselman and Jeffery Palermo around this topic.&lt;/p&gt;  &lt;p&gt;I'm not going to copy/paste his list, just go there and check it out if you're into MVC.&lt;/p&gt;
&lt;br /&gt;&lt;i&gt;Cross-posted from my blog at &lt;a href="http://weblogs.asp.net/jdanforth"&gt;http://weblogs.asp.net/jdanforth&lt;/a&gt;&lt;/i&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48431" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/johan/archive/tags/Podcasts/default.aspx">Podcasts</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/ASP.NET+MVC/default.aspx">ASP.NET MVC</category></item><item><title>ASP.NET MVC Supporting IronRuby and IronPython</title><link>http://blog.irm.se/blogs/johan/archive/2008/06/04/ASP.NET-MVC-Supporting-IronRuby-and-IronPython.aspx</link><pubDate>Wed, 04 Jun 2008 12:29:42 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48429</guid><dc:creator>johan</dc:creator><slash:comments>0</slash:comments><comments>http://blog.irm.se/blogs/johan/comments/48429.aspx</comments><wfw:commentRss>http://blog.irm.se/blogs/johan/commentrss.aspx?PostID=48429</wfw:commentRss><description>&lt;p&gt;I just picked up this answer to a &lt;a href="http://weblogs.asp.net/scottgu/archive/2008/06/01/asp-net-mvc-support-with-visual-web-developer-2008-express.aspx#6240898" target="_blank"&gt;comment on ScottGu's blog&lt;/a&gt;:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;I believe we will be showing using ASP.NET MVC with IronRuby and IronPython later this week at TechEd.&amp;#160; I don't think we've finalized what the tooling support will be - but you will be able to use these as language options with ASP.NET.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;It would have been cool to be at TechEd... &lt;/p&gt;
&lt;br /&gt;&lt;i&gt;Cross-posted from my blog at &lt;a href="http://weblogs.asp.net/jdanforth"&gt;http://weblogs.asp.net/jdanforth&lt;/a&gt;&lt;/i&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48429" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/johan/archive/tags/.NET+3.5/default.aspx">.NET 3.5</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/ASP.NET+MVC/default.aspx">ASP.NET MVC</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/Ruby/default.aspx">Ruby</category></item><item><title>OpenID Support for ASP.NET MVC</title><link>http://blog.irm.se/blogs/johan/archive/2008/05/21/OpenID-Support-for-ASP.NET-MVC.aspx</link><pubDate>Wed, 21 May 2008 15:40:47 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48426</guid><dc:creator>johan</dc:creator><slash:comments>0</slash:comments><comments>http://blog.irm.se/blogs/johan/comments/48426.aspx</comments><wfw:commentRss>http://blog.irm.se/blogs/johan/commentrss.aspx?PostID=48426</wfw:commentRss><description>&lt;p&gt;I've been monitoring the &lt;a href="http://openid.net/" target="_blank"&gt;OpenID&lt;/a&gt; progress for a while now, and when I saw &lt;a href="http://www.hanselman.com/blog/TheWeeklySourceCode25OpenIDEdition.aspx" target="_blank"&gt;this post from Scott Hanselman&lt;/a&gt; about how easy it is to add &lt;a href="http://openid.net/" target="_blank"&gt;OpenID&lt;/a&gt; support for &lt;a href="http://www.codeplex.com/aspnet" target="_blank"&gt;ASP.NET MVC&lt;/a&gt; through the use of the &lt;a href="http://code.google.com/p/dotnetopenid/" target="_blank"&gt;DotNetOpenId&lt;/a&gt; package, I had to give it a try. It it sure wasn't hard at all. &lt;/p&gt;  &lt;p&gt;If you go to the &lt;a href="http://code.google.com/p/dotnetopenid/" target="_blank"&gt;DotNetOpenId&lt;/a&gt; website and download their stuff, you even get sample code for ASP.NET MVC that you can copy/paste from. If you know some OpenID and some ASP.NET MVC it won't take more than a few minutes to get the integration working. &lt;/p&gt;  &lt;p&gt;Cool thing is also that if you get yourself an ID on &lt;a href="http://www.myopenid.com"&gt;www.myopenid.com&lt;/a&gt; (which is just one of many OpenID providers), you get Information card/CardSpace support as well! Oh I wish more websites could support this, I don't know how many different accounts and passwords I've created the last years. Thank God for &amp;quot;forgot my password&amp;quot; links... :)&lt;/p&gt;  &lt;p&gt;New to OpenID? &lt;a href="https://www.myopenid.com" target="_blank"&gt;Learn more&lt;/a&gt; about OpenID and &lt;a href="https://www.myopenid.com/signup" target="_blank"&gt;get your own&lt;/a&gt;.&lt;/p&gt;
&lt;br /&gt;&lt;i&gt;Cross-posted from my blog at &lt;a href="http://weblogs.asp.net/jdanforth"&gt;http://weblogs.asp.net/jdanforth&lt;/a&gt;&lt;/i&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48426" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/johan/archive/tags/ASP.NET+MVC/default.aspx">ASP.NET MVC</category><category domain="http://blog.irm.se/blogs/johan/archive/tags/OpenID/default.aspx">OpenID</category></item><item><title>New ASP.NET 3.5 Extensions Videos</title><link>http://blog.irm.se/blogs/johan/archive/2008/03/07/New-ASP.NET-3.5-Extensions-Videos.aspx</link><pubDate>Fri, 07 Mar 2008 07:34:13 GMT</pubDate><guid isPermaLink="false">b9e303c5-a40c-4002-ae9b-d6aca1a9a983:48402</guid><dc:creator>johan</dc:creator><slash:comments>0</slash:comments><comments>http://blog.irm.se/blogs/johan/comments/48402.aspx</comments><wfw:commentRss>http://blog.irm.se/blogs/johan/commentrss.aspx?PostID=48402</wfw:commentRss><description>&lt;p&gt;Videos and screencasts are great ways to learn new programming techniques, at least it works well for me. If you're interested in ASP.NET MVC, maybe you've already downloaded the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=38cc4cf1-773a-47e1-8125-ba3369bf54a3&amp;amp;displaylang=en" target="_blank"&gt;preview 2&lt;/a&gt; which was released a couple of days ago. In that case you also might want to head over to the ASP.NET webby and have a look at the &lt;a href="http://www.asp.net/learn/3.5-extensions-videos/default.aspx#mvc" target="_blank"&gt;4 new videos of ASP.NET MVC&lt;/a&gt;. It shows off viewing and editing data as well as the new Html helpers and testing.&lt;/p&gt;
&lt;br /&gt;&lt;i&gt;Cross-posted from my blog at &lt;a href="http://weblogs.asp.net/jdanforth"&gt;http://weblogs.asp.net/jdanforth&lt;/a&gt;&lt;/i&gt;&lt;img src="http://blog.irm.se/aggbug.aspx?PostID=48402" width="1" height="1"&gt;</description><category domain="http://blog.irm.se/blogs/johan/archive/tags/ASP.NET+MVC/default.aspx">ASP.NET MVC</category></item></channel></rss>