禁用MVC3中的下拉列表

时间:2014-02-18 06:44:17

标签: asp.net-mvc-3-areas

我填写了下拉列表: 控制器:

var db = new TransFormezEntities()           
ViewBag.fldCountry_ID = new SelectList(db.tblCountries, "fldCountry_ID", 
                                    "fldCountryName", stateDetails.fldCountry_ID)

查看

国家
<div class="display-field" id = "fldCountry_ID">
      @Html.DropDownList("fldCountry_ID", "[Select]")
</div>

我想让它成为只读或禁用我怎么能取悦?

1 个答案:

答案 0 :(得分:0)

尝试以下代码段

禁用

  Html.DropDownList("fldCountry_ID", ViewBag.fldCountry_ID ,
                                       new { @disabled = "disabled" })

只读

Html.DropDownList("fldCountry_ID", ViewBag.fldCountry_ID , 
                                  new { @readonly = "true" })