0
@using (Html.BeginForm("Boxing", "Company",FormMethod.Post))
{ 
    <div class="box">
        <div>
            <div class="left">
                <div class="topLabel">
                    Id No:</div>
                <div class="input_text_65">
                    @Html.TextBoxFor(m => m.Id)
                </div>
                <div class="botLabel">
                    percentt:
                </div>
                <div>
                    <input type="text" style="width: 50px" name="percent" />%
                </div>
            </div>
            <div class="lastDetailField">
                <div class="topLabel">
                    D/C:
                </div>
                <div class="select_110">
                    @Html.DropDownListFor(m => m.cType, new SelectList((IEnumerable<Model.cType>)ViewData[ViewDataKeys.cTypes]), "----")
                </div>
                <div class="margin_top_45">
                    <input id="submit" type="submit" value="submit" />
                </div>
            </div>
        </div>
    </div>
}

如果我没有在下拉列表中选择任何选项(选择选项标签“----”)并按下提交按钮,则不会发布表单,焦点将移至下拉列表

如果我删除可选标签,如下所示:

@Html.DropDownListFor(m => m.cType, new SelectList((IEnumerable)ViewData[ViewDataKeys.cTypes]))

那么它会工作得很好。我在想如果我要贴一个可选标签,这是否意味着我必须选择一个项目?即使我离开下拉列表并选择了可选标签,我也希望提交表单。

提前致谢!

4

1 回答 1

2

cType 上的模型/视图模式中是否有必需的属性?我认为客户端验证正在启动,但是因为您没有设置验证助手,所以您看不到该消息。如果您选择可选标签,表单将不会提交。

于 2011-08-18T09:34:23.553 回答