升级到测试版后,我在使用 Html.RadioButtonList 时遇到了问题。有人可以告诉我我做错了什么吗?
代码:
<% Html.RadioButtonList(
"voter" + voter.Id,
new SelectList(new[]{"yes","no","abstain"}, "yes")).Each(x => Response.Write(x)); %>
我得到的异常是:
[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
提前非常感谢!
罗布
最佳答案
看来您可能在 MVC 框架中发现了一个错误。 RadioButtonList 的其他重载似乎工作得很好,但特定的重载却失败了。
通过查看 Reflector(并使用堆栈跟踪),我看起来这一行出了问题:
return selectList.GetListItems().Select<ListItem, string>(delegate (ListItem item) {
return htmlHelper.RadioButton(name, item.Value, item.Selected, htmlAttributes);
}).ToArray<string>();
在 Microsoft.Web.Mvc.RadioListExtensions.RadioButtonListInternal 方法中。我认为这段代码在预览版 5 中运行良好?
关于asp.net - 单选按钮列表异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/214210/