<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2618729481054794561</id><updated>2011-12-21T19:25:03.915-08:00</updated><title type='text'>ASP.NET MVC</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://aspnet-mvc.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2618729481054794561/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://aspnet-mvc.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Elijah Manor</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh4.googleusercontent.com/-AtW_qomCJAo/AAAAAAAAAAI/AAAAAAAAKA4/4uIXuytCsyM/s512-c/photo.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2618729481054794561.post-5237368505265235073</id><published>2011-02-12T07:44:00.001-08:00</published><updated>2011-02-12T07:44:57.170-08:00</updated><title type='text'>Test Mobile Post</title><content type='html'>&lt;div&gt;&lt;p&gt;This is a test post with 2 pictures&lt;/p&gt;&lt;br/&gt;&lt;img src='http://lh6.ggpht.com/_L6DiZQsfJzs/TVaq9aLuFKI/AAAAAAAAJXI/OQuaPO18dYs/mask_vignette_legacy.png' /&gt;&lt;br/&gt;&lt;img src='http://lh4.ggpht.com/_L6DiZQsfJzs/TVaq-NAttcI/AAAAAAAAJXM/TabV1ugB61s/1297525378282.png' /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2618729481054794561-5237368505265235073?l=aspnet-mvc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspnet-mvc.blogspot.com/feeds/5237368505265235073/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2618729481054794561&amp;postID=5237368505265235073' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2618729481054794561/posts/default/5237368505265235073'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2618729481054794561/posts/default/5237368505265235073'/><link rel='alternate' type='text/html' href='http://aspnet-mvc.blogspot.com/2011/02/test-mobile-post.html' title='Test Mobile Post'/><author><name>Elijah Manor</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh4.googleusercontent.com/-AtW_qomCJAo/AAAAAAAAAAI/AAAAAAAAKA4/4uIXuytCsyM/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh6.ggpht.com/_L6DiZQsfJzs/TVaq9aLuFKI/AAAAAAAAJXI/OQuaPO18dYs/s72-c/mask_vignette_legacy.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2618729481054794561.post-5440382533407125160</id><published>2009-01-20T10:50:00.001-08:00</published><updated>2009-03-24T20:52:59.920-07:00</updated><title type='text'>ASP.NET MVC Html.RadioButtonList Blues</title><content type='html'>&lt;p&gt;Recently I upgraded our ASP.NET MVC project from Preview 5 to RC2. At first I thought the Html.RadioButtonList extension was removed completely, but then realized that it was no longer in the main MVC assembly, but was moved to the Futures project (although I don't know why).&lt;/p&gt;&lt;p&gt;The Preview 5 version of the Html.RadioButtonList rendered the following output...&lt;/p&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;a href="http://4.bp.blogspot.com/_L6DiZQsfJzs/Scmp4rZiIYI/AAAAAAAAGvA/OK1SegpLy1E/s1600-h/RadioButtonListPreview5.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/_L6DiZQsfJzs/Scmp4rZiIYI/AAAAAAAAGvA/OK1SegpLy1E/s400/RadioButtonListPreview5.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;However, once I got my code to compile I went to run my application only to find that it rendered two RadioButtons with no labels! Where did the labels go?&lt;/p&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;a href="http://2.bp.blogspot.com/_L6DiZQsfJzs/Scmp-rtA_8I/AAAAAAAAGvI/Ni3uATg50qk/s1600-h/RadioButtonLisRtm.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/_L6DiZQsfJzs/Scmp-rtA_8I/AAAAAAAAGvI/Ni3uATg50qk/s400/RadioButtonLisRtm.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;I pulled down the source code for the 1.0 release (just to make sure it wasn't fixed in the RTM as opposed to the RC2) and dove into the extension code. Nowhere did I see the labels being applied in the extension.&lt;/p&gt;&lt;pre class="brush: csharp; highlight: [30]"&gt;&lt;br /&gt;//C:\...\MVC-RTM\MVC\src\MvcFutures\Mvc\RadioExtensions.cs&lt;br /&gt;private static string[] RadioButtonListInternal(this HtmlHelper htmlHelper, string name, IEnumerable&amp;lt;SelectListItem&amp;gt; selectList, bool usedViewData, IDictionary&amp;lt;string, object&amp;gt; htmlAttributes) {&lt;br /&gt; if (String.IsNullOrEmpty(name)) {&lt;br /&gt;  throw new ArgumentException(MvcResources.Common_NullOrEmpty, "name");&lt;br /&gt; }&lt;br /&gt; if (selectList == null) {&lt;br /&gt;  throw new ArgumentNullException("selectList");&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; // If we haven't already used ViewData to get the entire list of items then we need to&lt;br /&gt; // use the ViewData-supplied value before using the parameter-supplied value.&lt;br /&gt; if (!usedViewData) {&lt;br /&gt;  object defaultValue = htmlHelper.ViewData.Eval(name);&lt;br /&gt;&lt;br /&gt;  if (defaultValue != null) {&lt;br /&gt;   IEnumerable defaultValues = new[] { defaultValue };&lt;br /&gt;   IEnumerable&amp;lt;string&amp;gt; values = from object value in defaultValues select Convert.ToString(value, CultureInfo.CurrentCulture);&lt;br /&gt;   HashSet&amp;lt;string&amp;gt; selectedValues = new HashSet&amp;lt;string&amp;gt;(values, StringComparer.OrdinalIgnoreCase);&lt;br /&gt;   List&amp;lt;SelectListItem&amp;gt; newSelectList = new List&amp;lt;SelectListItem&amp;gt;();&lt;br /&gt;&lt;br /&gt;   foreach (SelectListItem item in selectList) {&lt;br /&gt;    item.Selected = (item.Value != null) ? selectedValues.Contains(item.Value) : selectedValues.Contains(item.Text);&lt;br /&gt;    newSelectList.Add(item);&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   selectList = newSelectList;&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; IEnumerable&amp;lt;string&amp;gt; radioButtons = selectList.Select&amp;lt;SelectListItem, string&amp;gt;(item =&amp;gt; htmlHelper.RadioButton(name, item.Value, item.Selected, htmlAttributes));&lt;br /&gt;&lt;br /&gt; return radioButtons.ToArray();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Next I looked at the Unit Tests for the extesion. I was please to see tests for the RadioButtonList, but was shocked to see that the asserts were verifying html that didn't have any labels applied!&lt;/p&gt;&lt;pre class="brush: csharp; highlight: [11, 12, 13]"&gt;&lt;br /&gt;//C:\...\MVC-RTM\MVC\test\MvcFuturesTest\Mvc\Test\RadioExtensionsTest.cs&lt;br /&gt;[TestMethod]&lt;br /&gt;public void RadioButtonListItemSelected() {&lt;br /&gt; // Arrange&lt;br /&gt; HtmlHelper htmlHelper = TestHelper.GetHtmlHelper(new ViewDataDictionary());&lt;br /&gt;&lt;br /&gt; // Act&lt;br /&gt; string[] html = htmlHelper.RadioButtonList("FooList", GetRadioButtonListData(true));&lt;br /&gt;&lt;br /&gt; // Assert&lt;br /&gt; Assert.AreEqual(@"&amp;lt;input id=""FooList"" name=""FooList"" type=""radio"" value=""foo"" /&amp;gt;", html[0]);&lt;br /&gt; Assert.AreEqual(@"&amp;lt;input id=""FooList"" name=""FooList"" type=""radio"" value=""bar"" /&amp;gt;", html[1]);&lt;br /&gt; Assert.AreEqual(@"&amp;lt;input checked=""checked"" id=""FooList"" name=""FooList"" type=""radio"" value=""baz"" /&amp;gt;", html[2]);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;private static SelectList GetRadioButtonListData(bool selectBaz) {&lt;br /&gt; List&amp;lt;RadioItem&amp;gt; list = new List&amp;lt;RadioItem&amp;gt;();&lt;br /&gt; list.Add(new RadioItem { Text = "text-foo", Value = "foo" });&lt;br /&gt; list.Add(new RadioItem { Text = "text-bar", Value = "bar" });&lt;br /&gt; list.Add(new RadioItem { Text = "text-baz", Value = "baz" });&lt;br /&gt; return new SelectList(list, "value", "TEXT", selectBaz ? "baz" : "something-else");&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;private class RadioItem {&lt;br /&gt; public string Text {&lt;br /&gt;  get;&lt;br /&gt;  set;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public string Value {&lt;br /&gt;  get;&lt;br /&gt;  set;&lt;br /&gt; }&lt;br /&gt;}  &lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Where does that leave us? I guess using the Futures Html.RadioButtonList isn't all that helpful after all. So, instead I decided to loop through my DataSource and create individual Html.RadioButton and Label combinations.&lt;/p&gt;&lt;pre class="brush: csharp; highlight: [13, 14]"&gt;&lt;br /&gt;&amp;lt;!-- After using and looking at the code for the Html.RadioButtonList in the ASP.NET MVC 1.0 RTM codebase, &lt;br /&gt; I'm not sure how it is supposed to be useful. It only outputs the actual input radio button and doesn't render any corresponding labels. &lt;br /&gt; To get around this I ended up writing a foreach creating individual Html.RadioButton and labels --&amp;gt;&lt;br /&gt;&amp;lt;% &lt;br /&gt;var radioButtonList = new SelectList(new List&amp;lt;ListItem&amp;gt; {&lt;br /&gt;   new ListItem { Text = "Current", Value="false", Selected=true }, &lt;br /&gt;   new ListItem { Text = "Other", Value="true"}}, "Value", "Text", "false");&lt;br /&gt;var htmlAttributes = new Dictionary&amp;lt;string, object&amp;gt; { &lt;br /&gt;   { "class", "radioButtonList" },&lt;br /&gt;   { "onclick", "if(eval(this.value)) { $('#tblDate').show('slow'); } else { $('#tblDate').hide('slow'); }" }&lt;br /&gt;};&lt;br /&gt;foreach (var radiobutton in radioButtonList) { %&amp;gt;&lt;br /&gt;   &amp;lt;%=Html.RadioButton("rblDate", radiobutton.Value, radiobutton.Selected, htmlAttributes)%&amp;gt;&lt;br /&gt;   &amp;lt;label&amp;gt;&amp;lt;%=radiobutton.Text%&amp;gt;&amp;lt;/label&amp;gt;&lt;br /&gt;&amp;lt;% } %&amp;gt;   &lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2618729481054794561-5440382533407125160?l=aspnet-mvc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspnet-mvc.blogspot.com/feeds/5440382533407125160/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2618729481054794561&amp;postID=5440382533407125160' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2618729481054794561/posts/default/5440382533407125160'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2618729481054794561/posts/default/5440382533407125160'/><link rel='alternate' type='text/html' href='http://aspnet-mvc.blogspot.com/2009/01/test.html' title='ASP.NET MVC Html.RadioButtonList Blues'/><author><name>Elijah Manor</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh4.googleusercontent.com/-AtW_qomCJAo/AAAAAAAAAAI/AAAAAAAAKA4/4uIXuytCsyM/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_L6DiZQsfJzs/Scmp4rZiIYI/AAAAAAAAGvA/OK1SegpLy1E/s72-c/RadioButtonListPreview5.PNG' height='72' width='72'/><thr:total>0</thr:total></entry></feed>
