Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 2 访问IEnumerable mvc2单选按钮的值_Asp.net Mvc 2_Radio Button_Ienumerable - Fatal编程技术网

Asp.net mvc 2 访问IEnumerable mvc2单选按钮的值

Asp.net mvc 2 访问IEnumerable mvc2单选按钮的值,asp.net-mvc-2,radio-button,ienumerable,Asp.net Mvc 2,Radio Button,Ienumerable,我有一个是/否单选按钮,需要访问另一个aspx表单上的值。我不知道我做得对不对 主视图模型 [UIHint("YesNoEditorTemplate")] [DisplayName("Are you registered as blind (severely sight impaired)?")] public IEnumerable<RadioButtonViewModel> RegBlind { get; set; } public class RadioButtonViewM

我有一个是/否单选按钮,需要访问另一个aspx表单上的值。我不知道我做得对不对

主视图模型

[UIHint("YesNoEditorTemplate")]
[DisplayName("Are you registered as blind (severely sight impaired)?")]
public IEnumerable<RadioButtonViewModel> RegBlind { get; set; }
public class RadioButtonViewModel
{
    public string ID { get; set; }
    public string Name { get; set; }
    public int Value { get; set; }
    public string Text { get; set; }
}
控制器

List<RadioButtonViewModel> regBlindList = new List<RadioButtonViewModel>();
regBlindList.Add(CreateRadioButton("RegBlind", 1, "Yes"));
regBlindList.Add(CreateRadioButton("RegBlind", 0, "No"));
badgeViewModel.RegBlind = regBlindList;
这是正确的吗

提前感谢您的帮助


克莱尔

我认为问题在于,可枚举项永远不会存储所选的值,这只是在某种程度上丢失了

因此,您需要两个部分,一个用于存储值,另一个用于包含要显示的单选按钮

[DisplayName("Are you registered as blind (severely sight impaired)?")]
public int RegBlind { get; set; }

public IEnumerable<RadioButtonViewModel> RegBlindOptions { get; set; }
[DisplayName(“您是否注册为盲人(严重视力受损)?”)
public int RegBlind{get;set;}
公共IEnumerable RegBlindOptions{get;set;}
一旦您将其分类,您应该能够将EditorTemplate用作部分视图(不过,这可能意味着将其移出EditorTemplates目录,并移至相应的视图文件夹或共享视图)


这应该是可行的,或者很接近。如果没有,请查看生成的HTML并检查所有内容是否正确,然后仔细查看帖子标题中返回的内容:)

<%=Html.EditorFor(x => x.RegBlind)%>
if (Model.RegBlind.First().Value == 0)
[DisplayName("Are you registered as blind (severely sight impaired)?")]
public int RegBlind { get; set; }

public IEnumerable<RadioButtonViewModel> RegBlindOptions { get; set; }
<% Html.RenderPartial("YesNoEditorTemplate", Model.RegBlindOptions)%>