将HtmlHelperDropdown列表设置为禁用时,ModelState为false

时间:2018-12-01 09:50:03

标签: asp.net .net asp.net-mvc razor html-helper

我想证明如果数据不存在,则下拉列表将正常工作,但是当数据存在时,将禁用下拉列表。我尝试了只读,但是在为文本框工作时下拉菜单也不起作用。

@if (TrimsDataForEdit != null)
{
    <div class="form-group">
        @Html.LabelFor(m => m.SeasonId, new { @class = "col-lg-4 control-label" })
        <div class="col-lg-7">
            @Html.DropDownListFor(m => m.SeasonId, ViewBag.SeasonDDList as SelectList, new { @class = "form-control custom-select-box", @readonly = "readonly" })
            @Html.ValidationMessageFor(m => m.SeasonId, "", new { @class = "text-danger" })
        </div>
        <div class="col-lg-1">
            <span class="required">*</span>
        </div>
    </div>

}
else
{
    <div class="form-group">
        @Html.LabelFor(m => m.SeasonId, new { @class = "col-lg-4 control-label" })
        <div class="col-lg-7">
            @Html.DropDownListFor(m => m.SeasonId, ViewBag.SeasonDDList as SelectList, new { @class = "form-control custom-select-box" })
            @Html.ValidationMessageFor(m => m.SeasonId, "", new { @class = "text-danger" })
        </div>
        <div class="col-lg-1">
            <span class="required">*</span>
        </div>
    </div>

}

0 个答案:

没有答案