Reputation: 1983
After I upgraded to the beta, I'm having trouble with Html.RadioButtonList. Can someone show me what I'm doing wrong?
The code:
<% Html.RadioButtonList(
"voter" + voter.Id,
new SelectList(new[]{"yes","no","abstain"}, "yes")).Each(x => Response.Write(x)); %>
And the exception I get:
[ArgumentNullException: Value cannot be null.
Parameter name: value]
System.Web.Mvc.Html.InputExtensions.RadioButton(HtmlHelper htmlHelper, String name, Object value, Boolean isChecked, IDictionary`2 htmlAttributes) +214
Microsoft.Web.Mvc.<>c__DisplayClass1.<RadioButtonListInternal>b__0(ListItem item) in c:\dd\Cicero\src\Mvc\main\src\MvcFutures\Mvc\RadioExtensions.cs:86
System.Linq.WhereSelectListIterator`2.MoveNext() +107
System.Linq.Buffer`1..ctor(IEnumerable`1 source) +259
System.Linq.Enumerable.ToArray(IEnumerable`1 source) +81
Microsoft.Web.Mvc.RadioListExtensions.RadioButtonListInternal(HtmlHelper htmlHelper, String name, SelectList selectList, Boolean usedViewData, IDictionary`2 htmlAttributes) in c:\dd\Cicero\src\Mvc\main\src\MvcFutures\Mvc\RadioExtensions.cs:88
Microsoft.Web.Mvc.RadioListExtensions.RadioButtonList(HtmlHelper htmlHelper, String name, SelectList selectList) in c:\dd\Cicero\src\Mvc\main\src\MvcFutures\Mvc\RadioExtensions.cs:29
Many thanks in advance!
Rob
Upvotes: 4
Views: 1608
Reputation: 13685
It looks like you may have found a bug in the MVC framework. The other overloads of RadioButtonList seem to work just fine, but that particular overload barfs.
From looking at Reflector (and using the stack trace) I looks like things go awry at this line:
return selectList.GetListItems().Select<ListItem, string>(delegate (ListItem item) {
return htmlHelper.RadioButton(name, item.Value, item.Selected, htmlAttributes);
}).ToArray<string>();
In the Microsoft.Web.Mvc.RadioListExtensions.RadioButtonListInternal method. I assume this code worked fine in Preview 5?
Upvotes: 4