在asp.net MVC中提交单选按钮和复选框值为null

时间:2015-07-13 07:16:48

标签: asp.net-mvc

此处列出模型,同时单击提交按钮单选按钮和复选框值为空

@foreach (var item in Model)
    {
        @Html.HiddenFor(m => m[Countid].ActivityType)
        <div class=" ">
            <div class="clear">
            </div>
            @Html.Label("Group Name", "Group Name", new { @class = "control-label col-md-2", @style = "font-weight:700" })
            <label class="control-label col-md-2"> :  @item.PfpActivityGroup.ActivityGroupName</label>
        </div>
        <div class="">
            @Html.Label("Activity Type", "Activity Type", new { @class = "control-label col-md-2", @style = "font-weight:700" })
            <label class="control-label col-md-2"> :  @item.ActivityType</label>
            <div class="clear">
            </div>
        </div>

        if (item.PfpQsnCreationMasters != null)
        {
            <div class=" ">
                <label for="ActivityType" class="field-label">
                    Question Description
                </label>
                <label class="control-label col-md-2"> :  @item.PfpQsnCreationMasters.SurveyDesc</label>
                <div class="clear">
                </div>
                @Html.HiddenFor(m => m[Countid].PfpQsnCreationMasters.SurveyDesc)
                @Html.DropDownList("NoOfOptions", ViewData["NoOfOptions"] as SelectList, new { @class = "hide" })
                @Html.DropDownListFor(m => @item.PfpQsnCreationMasters.QuestionType, ViewData["QuestionType"] as SelectList, new { @class = "hide" })

                @if (item.Type == "TextBox")
                {
                    <div id="divTextBox">
                        @Html.TextBoxFor(x => item.txtQsnDesc);
                        @Html.HiddenFor(x => item.txtQsnDesc)
                        <div class="clear">
                        </div>
                    </div>
                }
                @if (item.Type == "RedioButton")
                {
                    <div >
                    @if (item.option1 != null)
                    {
                        @Html.RadioButtonFor(x => item.RadioOptionSelected, @item.option1)
                        <label class="control-label col-md-2"> @item.option1</label>
                        <div class="clear">
                        </div>
                    }
                    @if (item.option2 != null)
                    {
                        @Html.RadioButtonFor(x => item.RadioOptionSelected, @item.option2)
                        <label class="control-label col-md-2"> @item.option2</label>
                        <div class="clear">
                        </div>
                    }
                    @if (item.option3 != null)
                    {
                        @Html.RadioButtonFor(x => item.RadioOptionSelected, @item.option3)
                        <label class="control-label col-md-2"> @item.option3</label>
                        <div class="clear">
                        </div>
                    }
                   @if (item.option4 != null)
                    {
                        @Html.RadioButtonFor(x => item.RadioOptionSelected, @item.option4)
                        <label class="control-label col-md-2"> @item.option4</label>
                        <div class="clear">
                        </div>
                    }
                        @Html.HiddenFor(x => item.RadioOptionSelected)
                </div>
                }
                @if (item.Type == "CheckBox")
                {
                    <div id="divCheckBox">
                        @if (item.ListTextBox1 != null)
                        {

                            @Html.CheckBoxFor(x => item.IsOption1Selected)  <label class="control-label col-md-2"> @item.ListTextBox1</label>
                             @Html.HiddenFor(x => item.IsOption1Selected)
                            <div class="clear">
                            </div>
                        }
                        @if (item.ListTextBox2 != null)
                        {
                            @Html.CheckBoxFor(x => item.IsOption2Selected)  <label class="control-label col-md-2">   @item.ListTextBox2</label>
                            @Html.HiddenFor(x => item.IsOption2Selected)
                            <div class="clear">
                            </div>
                        }
                        @if (item.ListTextBox3 != null)
                        {
                            @Html.CheckBoxFor(x => item.IsOption3Selected) <label class="control-label col-md-2">   @item.ListTextBox3</label>
                             @Html.HiddenFor(x => item.IsOption3Selected)
                            <div class="clear">
                            </div>
                        }
                        @if (item.ListTextBox4 != null)
                        {
                            @Html.CheckBoxFor(x => item.IsOption4Selected) <label class="control-label col-md-2">  @item.ListTextBox4</label>
                             @Html.HiddenFor(x => item.IsOption4Selected)
                            <div class="clear">
                            </div>
                        }
                    </div>
                }

            </div>
        }
        <div class="clear">
        </div>
        <br />
        Countid = Countid + 1;
    }

1 个答案:

答案 0 :(得分:0)

我通常会将此添加为评论,但我缺少+50代表

尝试将其放在复选框的Model值上:

public class mymodel {

    [DisplayFormat(ConvertEmptyStringToNull = false)]
    public bool mycheckboxvalue { get; set; }

}