asp.net - 单选按钮列表异常

标签 asp.net asp.net-mvc

升级到测试版后,我在使用 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/

相关文章:

jquery - Url.Action 不适用于 getJSON

c# - 如何在用户配置文件中创建自定义附加字段

c# - 从 Controller 发送图像以在 MVC3 中查看

c# - WebRequest.GetResponse 等待完成

c# - 如何在 Enterprise Library 5.0 中更改数据库

c# - 在 Page_Load 中调用异步方法

asp.net - 有人在 Visual Studio Dev 机器上使用 Apple Mac OS 10.6 和 Parallels 5 取得成功吗?

javascript - 如何将组合框选定的值和单选按钮列表选中的值从 View 传递到 Controller

asp.net - 创建一个需要登录的 HotTowel 网站(facebook、twitter、google、microsoft)?

c# - 带有静态内容的 Html.dropdownlist