如何从动态生成的控件中读取复选框列表值

问题描述

我制作了一个调查模块

public class Survey
{

    public Int32 SurveyId { get; set; }

    public String Title { get; set; }

    public String Description { get; set; }

    public List<QuestionsEntity> lstQuestion { get; set; }

}

public class QuestionsEntity
{

        public Int32 Id { get; set; }

        public Int32 SurveyId { get; set; }
       
        public Int32 QuestionId { get; set; }
        public String QuestionType { get; set; }
       
        public List<QuestionsOptionsEntity> lstOptions { get; set; }

}

public class QuestionsOptionsEntity
{

        public Int32 Id { get; set; }
 
        public Int32 QuestionId { get; set; }
 
        public String Option { get; set; }

        public Boolean Selected { get; set; }

}

剃刀视图

@mode Survey

@for (int i = 0; i < Model.lstQuestion.Count(); i++)
{

<span class="form-label">@Model.lstQuestion[i].SNo.</span>

<span class="form-label">@Model.lstQuestion[i].Question</span>

<br />

 <br />

   @if (Model.lstQuestion[i].QuestionType.ToLower() == "chk")
    {

         @Html.HiddenFor(m => Model.lstQuestion[i].Id);
         @Html.HiddenFor(m => Model.lstQuestion[i].QuestionType);
         @Html.HiddenFor(m => Model.lstQuestion[i].SurveyId);


   for (int j = 0; j < Model.lstQuestion[i].lstOptions.Count; j++)
    {

       @Html.CheckBoxFor(m => m.lstQuestion[i].lstOptions[j].Selected,new 
  {
 
    @id = Model.lstQuestion[i].lstOptions[j].Id,@title = "Question " + Model.lstQuestion[i].SNo,@Group = Model.lstQuestion[i].SNo,@dataval = "req",@Name = Model.lstQuestion[i].SNo,});

  <span> @Model.lstQuestion[i].lstOptions[j].Option</span>


  <br /><br />

   }
 }
}

对于此当前代码,我在控制器中读取了选定的值。但是每当我应用组或名称进行验证时,我都无法读取复选框的选定值

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...