【问题标题】:HtmlAttributes not working for boolean property ASP.NET MVCHtmlAttributes 不适用于布尔属性 ASP.NET MVC
【发布时间】:2018-02-02 18:23:54
【问题描述】:

我有一个带有布尔属性的模型:

public bool IsWorking{ get; set; }

在我正在使用的视图中:

@Html.EditorFor(m => m.IsWorking, new BaseAdditionalData() { HtmlAttributes = new Dictionary<string, object> { { "id", "IsWorkingCustom" }, { "name", "IsWorkingCustom" } } })

但复选框的呈现 HTML 包含 id="IsWorking" name="IsWorking",因此没有任何变化。

【问题讨论】:

    标签: asp.net-mvc razor checkbox editorfor


    【解决方案1】:

    您必须将 name 更改为 Name 所以:

    @Html.EditorFor(m => m.IsWorking, new BaseAdditionalData { HtmlAttributes = new Dictionary<string, object> { { "id", "IsWorkingCustom" }, { "Name", "IsWorkingCustom" } } })
    

    【讨论】:

      猜你喜欢
      • 2015-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-06
      • 1970-01-01
      • 1970-01-01
      • 2016-10-17
      • 2011-08-24
      相关资源
      最近更新 更多