【问题标题】:Html.EnumDropDownListFor is not setting html attributesHtml.EnumDropDownListFor 未设置 html 属性
【发布时间】:2019-10-02 20:16:51
【问题描述】:

我正在尝试显示具有 css 类和禁用属性的枚举集的下拉列表。

这在 .Net Framework 4.6.2 项目中。我已经尝试设置 htmlAttribute 参数,就像文档(和所有博客文章)所建议的那样,但生成的 html 不包含 html 属性。

视图中的代码:

@Html.EnumDropDownListFor(model => model.FundingDataSource, htmlAttributes: new { @class = "disabled", @disabled = "disabled" })

预期

<select id="FundingDataSource" name="FundingDataSource" class="disabled" disabled="disabled"> 
    <option value=""></option>
    <option value="1">Option 1</option>
    <option selected="selected" value="2">Option 2</option>
</select>

实际HTML:

<select id="FundingDataSource" name="FundingDataSource"> 
    <option value=""></option>
    <option value="1">Option 1</option>
    <option selected="selected" value="2">Option 2</option>
</select>

对出了什么问题有什么想法或建议吗?

【问题讨论】:

    标签: c# asp.net-mvc razor


    【解决方案1】:

    与此post 类似,请尝试删除单词htmlAttributes

    @Html.EnumDropDownListFor(model => model.FundingDataSource, new { @class = "disabled", @disabled = "disabled" })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-19
      • 2012-06-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-17
      • 2012-03-25
      相关资源
      最近更新 更多