如何将使用Html.RadioButton()
HTML 帮助程序生成的单选按钮的值绑定到具有结构作为类型的字段?
不那么抽象:
CommonProject.Services.SearchBag.Effects:
public enum Effects
{
Any,
Solid,
Effect
}
在强类型 ViewData 中:
public class SearchBag{
public Effects EffectIndicator { get; set; }
}
在我看来(这实际上不起作用):
<%=Html.RadioButton("SearchBag.EffectIndicator", "Any", ViewData.Model.SearchBag.EffectIndicatorIsAny, new { @id = "SearchBag.EffectIndicatorAny" })%>
更新
它似乎工作一次..
最初它根据需要创建单选按钮,然后当您更改值并回发时,该值被正确绑定。然后在重新生成页面时,按钮的所有值都设置为您之前选择的值。